提交 59eaba7e 编写于 作者: O o2null

Merge branch 'feature/index' into 'develop'

Feature/index

See merge request o2oa/o2oa!1239
......@@ -24,161 +24,174 @@ import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
public class ActionListNextWithFilter extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionListNextWithFilter.class );
protected DateOperation dateOperation = new DateOperation();
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement ) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wraps = new ArrayList<>();
EffectivePerson currentPerson = this.effectivePerson(request);
Long total = 0L;
List<AttendanceSelfHoliday> detailList = null;
List<String> topUnitNames = new ArrayList<String>();
List<String> unitNames = new ArrayList<String>();
List<String> unitNameList = null;
WrapIn wrapIn = null;
Boolean check = true;
Date startDate = null;
Date endDate = null;
try {
wrapIn = this.convertToWrapIn( jsonElement, WrapIn.class );
startDate = dateOperation.getDateFromString( wrapIn.getStartdateString() + " 00:00:00");
endDate = dateOperation.getDateFromString( wrapIn.getEnddateString() + " 23:59:59");
if( endDate == null ){
endDate = dateOperation.getLastDateInMonth( new Date() );
}
if( startDate == null ){
startDate = dateOperation.getFirstDateInMonth( new Date() );
}
if( startDate.after( endDate ) ){
startDate = dateOperation.getFirstDateInMonth( new Date() );
}
wrapIn.setStartdate(startDate);
wrapIn.setEnddate(endDate);
} catch (Exception e ) {
check = false;
Exception exception = new ExceptionWrapInConvert( e, jsonElement );
result.error( exception );
logger.error( e, currentPerson, request, null);
}
if(check ){
try {
EntityManagerContainer emc = EntityManagerContainerFactory.instance().create();
Business business = new Business(emc);
//查询出ID对应的记录的sequence
Object sequence = null;
if( id == null || "(0)".equals(id) || id.isEmpty() ){
//logger.info( "第一页查询,没有id传入" );
}else{
if (!StringUtils.equalsIgnoreCase(id,StandardJaxrsAction.EMPTY_SYMBOL)) {
sequence = PropertyUtils.getProperty(emc.find( id, AttendanceSelfHoliday.class ), JpaObject.sequence_FIELDNAME);
}
}
//处理一下顶层组织,查询下级顶层组织
if( StringUtils.isNotEmpty( wrapIn.getQ_topUnitName() ) ){
topUnitNames.add( wrapIn.getQ_topUnitName() );
try{
unitNameList = userManagerService.listSubUnitNameWithParent( wrapIn.getQ_topUnitName() );
}catch(Exception e){
Exception exception = new ExceptionSelfHolidayProcess( e,
"系统根据顶层组织名称查询所有下级组织列表时发生异常.Name:" + wrapIn.getQ_topUnitName() );
result.error( exception );
logger.error( e, currentPerson, request, null);
}
if( unitNameList != null && unitNameList.size() > 0 ){
for( String unitName : unitNameList){
topUnitNames.add( unitName );
}
}
wrapIn.setTopUnitNames( topUnitNames );
}
//处理一下组织,查询下级组织
if( StringUtils.isNotEmpty( wrapIn.getQ_unitName() ) ){
unitNames.add(wrapIn.getQ_unitName());
try{
unitNameList = userManagerService.listSubUnitNameWithParent( wrapIn.getQ_unitName() );
}catch(Exception e){
Exception exception = new ExceptionSelfHolidayProcess( e, "系统根据组织名称查询所有下级组织列表时发生异常.Name:" + wrapIn.getQ_unitName() );
result.error( exception );
logger.error( e, currentPerson, request, null);
}
if( unitNameList != null && unitNameList.size() > 0 ){
for( String unitName : unitNameList){
unitNames.add( unitName );
}
}
wrapIn.setUnitNames(unitNames);
}
//从数据库中查询符合条件的一页数据对象
detailList = business.getAttendanceSelfHolidayFactory().listIdsNextWithFilter( id, count, sequence, wrapIn );
//从数据库中查询符合条件的对象总数
total = business.getAttendanceSelfHolidayFactory().getCountWithFilter( wrapIn );
//将所有查询出来的有状态的对象转换为可以输出的过滤过属性的对象
wraps = Wo.copier.copy( detailList );
} catch (Throwable th) {
th.printStackTrace();
result.error(th);
}
}
result.setCount( total );
result.setData(wraps);
return result;
}
public static class WrapIn extends WrapInFilter{
String startdateString;
String enddateString;
Date startdate = null;
Date enddate = null;
public String getStartdateString() {
return startdateString;
}
public void setStartdateString(String startdateString) {
this.startdateString = startdateString;
}
public String getEnddateString() {
return enddateString;
}
public void setEnddateString(String enddateString) {
this.enddateString = enddateString;
}
public Date getStartdate() {
return startdate;
}
public void setStartdate(Date startdate) {
this.startdate = startdate;
}
public Date getEnddate() {
return enddate;
}
public void setEnddate(Date enddate) {
this.enddate = enddate;
}
}
public static class Wo extends AttendanceSelfHoliday {
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<AttendanceSelfHoliday, Wo> copier =
WrapCopierFactory.wo(AttendanceSelfHoliday.class, Wo.class, null,JpaObject.FieldsInvisible);
}
private static Logger logger = LoggerFactory.getLogger(ActionListNextWithFilter.class);
protected DateOperation dateOperation = new DateOperation();
protected ActionResult<List<Wo>> execute(HttpServletRequest request, EffectivePerson effectivePerson, String id,
Integer count, JsonElement jsonElement) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wraps = new ArrayList<>();
EffectivePerson currentPerson = this.effectivePerson(request);
Long total = 0L;
List<AttendanceSelfHoliday> detailList = null;
List<String> topUnitNames = new ArrayList<String>();
List<String> unitNames = new ArrayList<String>();
List<String> unitNameList = null;
WrapIn wrapIn = null;
Boolean check = true;
Date startDate = null;
Date endDate = null;
try {
wrapIn = this.convertToWrapIn(jsonElement, WrapIn.class);
if (StringUtils.isNotBlank(wrapIn.getStartdateString())) {
startDate = dateOperation.getDateFromString(wrapIn.getStartdateString() + " 00:00:00");
}
if (StringUtils.isNotBlank(wrapIn.getEnddateString())) {
endDate = dateOperation.getDateFromString(wrapIn.getEnddateString() + " 23:59:59");
}
if (endDate == null) {
endDate = dateOperation.getLastDateInMonth(new Date());
}
if (startDate == null) {
startDate = dateOperation.getFirstDateInMonth(new Date());
}
if (startDate.after(endDate)) {
startDate = dateOperation.getFirstDateInMonth(new Date());
}
wrapIn.setStartdate(startDate);
wrapIn.setEnddate(endDate);
} catch (Exception e) {
check = false;
Exception exception = new ExceptionWrapInConvert(e, jsonElement);
result.error(exception);
logger.error(e, currentPerson, request, null);
}
if (check) {
try {
EntityManagerContainer emc = EntityManagerContainerFactory.instance().create();
Business business = new Business(emc);
// 查询出ID对应的记录的sequence
Object sequence = null;
if (id == null || "(0)".equals(id) || id.isEmpty()) {
// logger.info( "第一页查询,没有id传入" );
} else {
if (!StringUtils.equalsIgnoreCase(id, StandardJaxrsAction.EMPTY_SYMBOL)) {
sequence = PropertyUtils.getProperty(emc.find(id, AttendanceSelfHoliday.class),
JpaObject.sequence_FIELDNAME);
}
}
// 处理一下顶层组织,查询下级顶层组织
if (StringUtils.isNotEmpty(wrapIn.getQ_topUnitName())) {
topUnitNames.add(wrapIn.getQ_topUnitName());
try {
unitNameList = userManagerService.listSubUnitNameWithParent(wrapIn.getQ_topUnitName());
} catch (Exception e) {
Exception exception = new ExceptionSelfHolidayProcess(e,
"系统根据顶层组织名称查询所有下级组织列表时发生异常.Name:" + wrapIn.getQ_topUnitName());
result.error(exception);
logger.error(e, currentPerson, request, null);
}
if (unitNameList != null && unitNameList.size() > 0) {
for (String unitName : unitNameList) {
topUnitNames.add(unitName);
}
}
wrapIn.setTopUnitNames(topUnitNames);
}
// 处理一下组织,查询下级组织
if (StringUtils.isNotEmpty(wrapIn.getQ_unitName())) {
unitNames.add(wrapIn.getQ_unitName());
try {
unitNameList = userManagerService.listSubUnitNameWithParent(wrapIn.getQ_unitName());
} catch (Exception e) {
Exception exception = new ExceptionSelfHolidayProcess(e,
"系统根据组织名称查询所有下级组织列表时发生异常.Name:" + wrapIn.getQ_unitName());
result.error(exception);
logger.error(e, currentPerson, request, null);
}
if (ListTools.isNotEmpty(unitNameList)) {
for (String unitName : unitNameList) {
unitNames.add(unitName);
}
}
wrapIn.setUnitNames(unitNames);
}
// 从数据库中查询符合条件的一页数据对象
detailList = business.getAttendanceSelfHolidayFactory().listIdsNextWithFilter(id, count, sequence,
wrapIn);
// 从数据库中查询符合条件的对象总数
total = business.getAttendanceSelfHolidayFactory().getCountWithFilter(wrapIn);
// 将所有查询出来的有状态的对象转换为可以输出的过滤过属性的对象
wraps = Wo.copier.copy(detailList);
} catch (Throwable th) {
th.printStackTrace();
result.error(th);
}
}
result.setCount(total);
result.setData(wraps);
return result;
}
public static class WrapIn extends WrapInFilter {
String startdateString;
String enddateString;
Date startdate = null;
Date enddate = null;
public String getStartdateString() {
return startdateString;
}
public void setStartdateString(String startdateString) {
this.startdateString = startdateString;
}
public String getEnddateString() {
return enddateString;
}
public void setEnddateString(String enddateString) {
this.enddateString = enddateString;
}
public Date getStartdate() {
return startdate;
}
public void setStartdate(Date startdate) {
this.startdate = startdate;
}
public Date getEnddate() {
return enddate;
}
public void setEnddate(Date enddate) {
this.enddate = enddate;
}
}
public static class Wo extends AttendanceSelfHoliday {
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<AttendanceSelfHoliday, Wo> copier = WrapCopierFactory.wo(AttendanceSelfHoliday.class,
Wo.class, null, JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
......@@ -4,183 +4,183 @@ import org.apache.commons.lang3.StringUtils;
public class SlicePropertiesBuilder {
private SlicePropertiesBuilder() {
// nothing
}
private SlicePropertiesBuilder() {
// nothing
}
public static String driver_db2 = "com.ibm.db2.jcc.DB2Driver";
public static String driver_oracle = "oracle.jdbc.OracleDriver";
public static String driver_mysql = "com.mysql.cj.jdbc.Driver";
public static String driver_postgresql = "org.postgresql.Driver";
public static String driver_informix = "com.informix.jdbc.IfxDriver";
public static String driver_h2 = "org.h2.Driver";
public static String driver_dm = "dm.jdbc.driver.DmDriver";
public static String driver_sqlserver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
public static String driver_gbase = "com.gbasedbt.jdbc.Driver";
public static String driver_gbasemysql = "com.gbase.cj.jdbc.Driver";
public static String driver_kingbase = "com.kingbase.Driver";
public static String driver_kingbase8 = "com.kingbase8.Driver";
public static String driver_oscar = "com.oscar.Driver";
/* 避免db2在aix版本和lwl版本字段长度不一致的问题 */
public static String dictionary_db2 = "db2(createPrimaryKeys=false,characterColumnSize=255,maxColumnNameLength=128,maxIndexNameLength=128,maxConstraintNameLength=128)";
public static String dictionary_oracle = "oracle(maxTableNameLength=128,maxColumnNameLength=128,maxIndexNameLength=128,maxConstraintNameLength=128,maxEmbeddedClobSize=-1,maxEmbeddedBlobSize=-1)";
public static String dictionary_mysql = "mysql(clobTypeName=LONGTEXT,blobTypeName=LONGBLOB,createPrimaryKeys=false,maxIndexesPerTable=64)";
public static String dictionary_postgresql = "postgres";
public static String dictionary_informix = "informix";
public static String dictionary_h2 = "org.apache.openjpa.jdbc.sql.H2Dictionary";
public static String dictionary_dm = "com.x.base.core.openjpa.jdbc.sql.DMDictionary";
public static String dictionary_sqlserver = "sqlserver(schemaCase=preserve)";
public static String dictionary_gbase = "com.x.base.core.openjpa.jdbc.sql.GBaseDictionary";
public static String dictionary_gbasemysql = "com.x.base.core.openjpa.jdbc.sql.GBaseMySQLDictionary";
public static String dictionary_kingbase = "com.x.base.core.openjpa.jdbc.sql.KingbaseDictionary";
public static String dictionary_kingbase8 = "com.x.base.core.openjpa.jdbc.sql.Kingbase8Dictionary";
public static String dictionary_oscar = "com.x.base.core.openjpa.jdbc.sql.OscarDictionary";
public static String driver_db2 = "com.ibm.db2.jcc.DB2Driver";
public static String driver_oracle = "oracle.jdbc.OracleDriver";
public static String driver_mysql = "com.mysql.cj.jdbc.Driver";
public static String driver_postgresql = "org.postgresql.Driver";
public static String driver_informix = "com.informix.jdbc.IfxDriver";
public static String driver_h2 = "org.h2.Driver";
public static String driver_dm = "dm.jdbc.driver.DmDriver";
public static String driver_sqlserver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
public static String driver_gbase = "com.gbasedbt.jdbc.Driver";
public static String driver_gbasemysql = "com.gbase.cj.jdbc.Driver";
public static String driver_kingbase = "com.kingbase.Driver";
public static String driver_kingbase8 = "com.kingbase8.Driver";
public static String driver_oscar = "com.oscar.Driver";
/* 避免db2在aix版本和lwl版本字段长度不一致的问题 */
public static String dictionary_db2 = "db2(createPrimaryKeys=false,characterColumnSize=255,maxColumnNameLength=128,maxIndexNameLength=128,maxConstraintNameLength=128)";
public static String dictionary_oracle = "oracle(maxTableNameLength=128,maxColumnNameLength=128,maxIndexNameLength=128,maxConstraintNameLength=128,maxEmbeddedClobSize=-1,maxEmbeddedBlobSize=-1)";
public static String dictionary_mysql = "mysql(clobTypeName=LONGTEXT,blobTypeName=LONGBLOB,createPrimaryKeys=false,maxIndexesPerTable=64)";
public static String dictionary_postgresql = "postgres";
public static String dictionary_informix = "informix";
public static String dictionary_h2 = "org.apache.openjpa.jdbc.sql.H2Dictionary";
public static String dictionary_dm = "com.x.base.core.openjpa.jdbc.sql.DMDictionary";
public static String dictionary_sqlserver = "sqlserver(schemaCase=preserve)";
public static String dictionary_gbase = "com.x.base.core.openjpa.jdbc.sql.GBaseDictionary";
public static String dictionary_gbasemysql = "com.x.base.core.openjpa.jdbc.sql.GBaseMySQLDictionary";
public static String dictionary_kingbase = "com.x.base.core.openjpa.jdbc.sql.KingbaseDictionary";
public static String dictionary_kingbase8 = "com.x.base.core.openjpa.jdbc.sql.Kingbase8Dictionary";
public static String dictionary_oscar = "com.x.base.core.openjpa.jdbc.sql.OscarDictionary";
public static String validationQuery_db2 = "select 1 from sysibm.sysdummy1";
public static String validationQuery_oracle = "select 1 from dual";
public static String validationQuery_mysql = "select 1";
public static String validationQuery_postgresql = "select 1";
public static String validationQuery_informix = "select 1";
public static String validationQuery_h2 = "select 1";
public static String validationQuery_dm = "select getdate()";
public static String validationQuery_sqlserver = "select 1";
public static String validationQuery_gbase = "select 1 from dual";
public static String validationQuery_gbasemysql = "select now()";
public static String validationQuery_kingbase = "select now()";
public static String validationQuery_kingbase8 = "select now()";
public static String validationQuery_oscar = "select 1 from dual";
public static String validationQuery_db2 = "select 1 from sysibm.sysdummy1";
public static String validationQuery_oracle = "select 1 from dual";
public static String validationQuery_mysql = "select 1";
public static String validationQuery_postgresql = "select 1";
public static String validationQuery_informix = "select 1";
public static String validationQuery_h2 = "select 1";
public static String validationQuery_dm = "select getdate()";
public static String validationQuery_sqlserver = "select 1";
public static String validationQuery_gbase = "select 1 from dual";
public static String validationQuery_gbasemysql = "select now()";
public static String validationQuery_kingbase = "select now()";
public static String validationQuery_kingbase8 = "select now()";
public static String validationQuery_oscar = "select 1 from dual";
// 单个slice名称
public static String getName(Integer i) throws Exception {
try {
return "s" + ((1001 + i) + "").substring(1);
} catch (Exception e) {
throw new Exception("can not create slice name property", e);
}
}
// 单个slice名称
public static String getName(Integer i) throws Exception {
try {
return "s" + ((1001 + i) + "").substring(1);
} catch (Exception e) {
throw new Exception("can not create slice name property", e);
}
}
public static String driverClassNameOfUrl(String url) throws Exception {
if (StringUtils.containsIgnoreCase(url, "jdbc:db2:")) {
return driver_db2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oracle:")) {
return driver_oracle;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:mysql:")) {
return driver_mysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:postgresql:")) {
return driver_postgresql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:informix-sqli:")) {
return driver_informix;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbasedbt-sqli:")) {
return driver_gbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbase:")) {
return driver_gbasemysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:h2:tcp:")) {
return driver_h2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:dm:")) {
return driver_dm;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:sqlserver:")) {
return driver_sqlserver;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase:")) {
return driver_kingbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase8:")) {
return driver_kingbase8;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oscar:")) {
return driver_oscar;
}
throw new Exception("can not get driverClassName of url: " + url + ".");
}
public static String driverClassNameOfUrl(String url) throws Exception {
if (StringUtils.containsIgnoreCase(url, "jdbc:db2:")) {
return driver_db2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oracle:")) {
return driver_oracle;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:mysql:")) {
return driver_mysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:postgresql:")) {
return driver_postgresql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:informix-sqli:")) {
return driver_informix;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbasedbt-sqli:")) {
return driver_gbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbase:")) {
return driver_gbasemysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:h2:tcp:")) {
return driver_h2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:dm:")) {
return driver_dm;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:sqlserver:")) {
return driver_sqlserver;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase:")) {
return driver_kingbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase8:")) {
return driver_kingbase8;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oscar:")) {
return driver_oscar;
}
throw new Exception("can not get driverClassName of url: " + url + ".");
}
public static String dictionaryOfUrl(String url) throws Exception {
if (StringUtils.containsIgnoreCase(url, "jdbc:db2:")) {
return dictionary_db2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oracle:")) {
return dictionary_oracle;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:mysql:")) {
return dictionary_mysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:postgresql:")) {
return dictionary_postgresql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:informix-sqli:")) {
return dictionary_informix;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbasedbt-sqli:")) {
return dictionary_gbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbase:")) {
return dictionary_gbasemysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:h2:tcp:")) {
return dictionary_h2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:dm:")) {
return dictionary_dm;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:sqlserver:")) {
return dictionary_sqlserver;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase:")) {
return dictionary_kingbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase8:")) {
return dictionary_kingbase8;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oscar:")) {
return dictionary_oscar;
}
throw new Exception("can not get dictionary of url: " + url + ".");
}
public static String dictionaryOfUrl(String url) throws Exception {
if (StringUtils.containsIgnoreCase(url, "jdbc:db2:")) {
return dictionary_db2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oracle:")) {
return dictionary_oracle;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:mysql:")) {
return dictionary_mysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:postgresql:")) {
return dictionary_postgresql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:informix-sqli:")) {
return dictionary_informix;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbasedbt-sqli:")) {
return dictionary_gbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbase:")) {
return dictionary_gbasemysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:h2:tcp:")) {
return dictionary_h2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:dm:")) {
return dictionary_dm;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:sqlserver:")) {
return dictionary_sqlserver;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase:")) {
return dictionary_kingbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase8:")) {
return dictionary_kingbase8;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oscar:")) {
return dictionary_oscar;
}
throw new Exception("can not get dictionary of url: " + url + ".");
}
public static boolean hasSchemaOfUrl(String url) throws Exception {
if (StringUtils.containsIgnoreCase(url, "jdbc:db2:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oracle:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:mysql:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:postgresql:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:informix-sqli:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbasedbt-sqli:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbase:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:h2:tcp:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:dm:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:sqlserver:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase8:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oscar:")) {
return true;
}
throw new Exception("can not get schema of url: " + url + ".");
}
public static boolean hasSchemaOfUrl(String url) throws Exception {
if (StringUtils.containsIgnoreCase(url, "jdbc:db2:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oracle:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:mysql:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:postgresql:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:informix-sqli:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbasedbt-sqli:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbase:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:h2:tcp:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:dm:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:sqlserver:")) {
return false;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase8:")) {
return true;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oscar:")) {
return true;
}
throw new Exception("can not get schema of url: " + url + ".");
}
public static String validationQueryOfUrl(String url) throws Exception {
if (StringUtils.containsIgnoreCase(url, "jdbc:db2:")) {
return validationQuery_db2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oracle:")) {
return validationQuery_oracle;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:mysql:")) {
return validationQuery_mysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:postgresql:")) {
return validationQuery_postgresql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:informix-sqli:")) {
return validationQuery_informix;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbasedbt-sqli:")) {
return validationQuery_gbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbase:")) {
return validationQuery_gbasemysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:h2:tcp:")) {
return validationQuery_h2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:dm:")) {
return validationQuery_dm;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:sqlserver:")) {
return validationQuery_sqlserver;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase:")) {
return validationQuery_kingbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase8:")) {
return validationQuery_kingbase8;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oscar:")) {
return validationQuery_oscar;
}
throw new Exception("can not get schema of url: " + url + ".");
}
public static String validationQueryOfUrl(String url) throws Exception {
if (StringUtils.containsIgnoreCase(url, "jdbc:db2:")) {
return validationQuery_db2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oracle:")) {
return validationQuery_oracle;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:mysql:")) {
return validationQuery_mysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:postgresql:")) {
return validationQuery_postgresql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:informix-sqli:")) {
return validationQuery_informix;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbasedbt-sqli:")) {
return validationQuery_gbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:gbase:")) {
return validationQuery_gbasemysql;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:h2:tcp:")) {
return validationQuery_h2;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:dm:")) {
return validationQuery_dm;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:sqlserver:")) {
return validationQuery_sqlserver;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase:")) {
return validationQuery_kingbase;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:kingbase8:")) {
return validationQuery_kingbase8;
} else if (StringUtils.containsIgnoreCase(url, "jdbc:oscar:")) {
return validationQuery_oscar;
}
throw new Exception("can not get schema of url: " + url + ".");
}
}
\ No newline at end of file
......@@ -12,251 +12,259 @@ import com.x.base.core.project.tools.Crypto;
public class ExternalDataSource extends ConfigObject {
// 无需保存
private transient String _password;
public ExternalDataSource() {
}
public static final Boolean DEFAULT_ENABLE = false;
public static final String DEFAULT_URL = "jdbc:mysql://127.0.0.1:3306/X?autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8";
public static final String DEFAULT_USERNAME = "root";
public static final String DEFAULT_PASSWORD = "password";
public static final String DEFAULT_DRIVERCLASSNAME = "";
public static final String DEFAULT_DICTIONARY = "";
public static final Integer DEFAULT_MAXTOTAL = 100;
public static final Integer DEFAULT_MAXIDLE = 0;
public static final Boolean DEFAULT_STATENABLE = true;
public static final String DEFAULT_STATFILTER = "mergeStat";
public static final List<String> DEFAULT_INCLUDES = new ArrayList<>();
public static final List<String> DEFAULT_EXCLUDES = new ArrayList<>();
public static final Integer DEFAULT_SLOWSQLMILLIS = 2000;
public static final String DEFAULT_LOGLEVEL = "ERROR";
public static final String DEFAULT_TRANSACTIONISOLATION = "read-committed";
public static final Boolean DEFAULT_TESTCONNECTIONONCHECKIN = false;
public static final Boolean DEFAULT_TESTCONNECTIONONCHECKOUT = false;
public static final Integer DEFAULT_MAXIDLETIME = 300;
public static final Boolean DEFAULT_AUTOCOMMIT = false;
public static final Boolean DEFAULT_TRACESQLENABLE = false;
public static ExternalDataSource defaultInstance() {
ExternalDataSource o = new ExternalDataSource();
o.enable = DEFAULT_ENABLE;
o.url = DEFAULT_URL;
o.username = DEFAULT_USERNAME;
o.password = DEFAULT_PASSWORD;
o.driverClassName = DEFAULT_DRIVERCLASSNAME;
o.dictionary = DEFAULT_DICTIONARY;
o.maxTotal = DEFAULT_MAXTOTAL;
o.maxIdle = DEFAULT_MAXIDLE;
o.statEnable = DEFAULT_STATENABLE;
o.statFilter = DEFAULT_STATFILTER;
o.slowSqlMillis = DEFAULT_SLOWSQLMILLIS;
o.includes = DEFAULT_INCLUDES;
o.excludes = DEFAULT_EXCLUDES;
o.logLevel = DEFAULT_LOGLEVEL;
o.transactionIsolation = DEFAULT_TRANSACTIONISOLATION;
o.testConnectionOnCheckin = DEFAULT_TESTCONNECTIONONCHECKIN;
o.testConnectionOnCheckout = DEFAULT_TESTCONNECTIONONCHECKOUT;
o.maxIdleTime = DEFAULT_MAXIDLETIME;
o.autoCommit = DEFAULT_AUTOCOMMIT;
o.traceSqlEnable = DEFAULT_TRACESQLENABLE;
return o;
}
@FieldDescribe("是否启用,如果启用多个数据库,那么必须是相同类型的,不能混用,且用户名密码必须一致.")
private Boolean enable;
@FieldDescribe("jdbc连接地址.")
private String url;
@FieldDescribe("数据库jdbc连接用户名.")
private String username;
@FieldDescribe("数据库jdbc连接密码.")
private String password;
@FieldDescribe("数据库驱动类名.")
private String driverClassName;
@FieldDescribe("方言类.")
private String dictionary;
@FieldDescribe("最大使用连接数.")
private Integer maxTotal;
@FieldDescribe("最大空闲连接数.")
private Integer maxIdle;
@FieldDescribe("启用统计,默认启用.")
private Boolean statEnable;
@FieldDescribe("统计方式配置,默认mergeStat.")
private String statFilter;
@FieldDescribe("执行缓慢sql毫秒数,默认2000毫秒,执行缓慢的sql将被单独记录.")
private Integer slowSqlMillis;
@FieldDescribe("设置此数据库存储的类,默认情况下存储所有类型,如果需要对每个类进行单独的控制以达到高性能,可以将不同的类存储到不同的节点上提高性能.可以使用通配符*.")
private List<String> includes;
@FieldDescribe("在此节点上不存储的类,和includes一起设置实际存储的类,可以使用通配符*.")
private List<String> excludes;
@FieldDescribe("默认日志级别,FATAL, ERROR, WARN, INFO, TRACE. 完整的配置为DefaultLevel=WARN, Tool=TRACE, Enhance=TRACE, METADATA=TRACE, Runtime=TRACE, Query=TRACE, DataCache=TRACE, JDBC=TRACE, SQL=TRACE.")
private String logLevel = DEFAULT_LOGLEVEL;
@FieldDescribe("事务隔离级别:default,none,read-uncommitted,read-committed,repeatable-read,serializable.默认使用default(数据库设置的事务级别).")
private String transactionIsolation;
@FieldDescribe("测试入池连接,默认false.")
private Boolean testConnectionOnCheckin;
@FieldDescribe("测试出池连接,默认false.")
private Boolean testConnectionOnCheckout;
@FieldDescribe("空闲阈值,默认300秒.")
private Integer maxIdleTime;
@FieldDescribe("自动提交,默认为false.")
private Boolean autoCommit = DEFAULT_AUTOCOMMIT;
@FieldDescribe("启用sql跟踪.")
private Boolean traceSqlEnable = DEFAULT_TRACESQLENABLE;
public Boolean getTraceSqlEnable() {
return (null == this.traceSqlEnable) ? DEFAULT_TRACESQLENABLE : this.traceSqlEnable;
}
public Boolean getAutoCommit() {
return (null == this.autoCommit) ? DEFAULT_AUTOCOMMIT : this.autoCommit;
}
public Integer getMaxIdleTime() {
return maxIdleTime == null ? DEFAULT_MAXIDLETIME : this.maxIdleTime;
}
public Boolean getTestConnectionOnCheckin() {
return this.testConnectionOnCheckin == null ? DEFAULT_TESTCONNECTIONONCHECKIN : this.testConnectionOnCheckin;
}
public Boolean getTestConnectionOnCheckout() {
return this.testConnectionOnCheckout == null ? DEFAULT_TESTCONNECTIONONCHECKOUT : this.testConnectionOnCheckout;
}
public String getTransactionIsolation() {
return StringUtils.isEmpty(this.transactionIsolation) ? DEFAULT_TRANSACTIONISOLATION
: this.transactionIsolation;
}
public String getLogLevel() {
return StringUtils.isEmpty(this.logLevel) ? DEFAULT_LOGLEVEL : this.logLevel;
}
public String getDriverClassName() throws Exception {
return StringUtils.isEmpty(this.driverClassName) ? SlicePropertiesBuilder.driverClassNameOfUrl(this.url)
: this.driverClassName;
}
public String getDictionary() throws Exception {
return StringUtils.isEmpty(this.dictionary) ? SlicePropertiesBuilder.dictionaryOfUrl(this.url)
: this.dictionary;
}
public Integer getSlowSqlMillis() {
return (null == this.slowSqlMillis || this.slowSqlMillis < 1) ? DEFAULT_SLOWSQLMILLIS : this.slowSqlMillis;
}
public String getStatFilter() {
return StringUtils.isEmpty(this.statFilter) ? DEFAULT_STATFILTER : this.statFilter;
}
public Boolean getStatEnable() {
return null == statEnable ? DEFAULT_STATENABLE : this.statEnable;
}
public Integer getMaxIdle() {
if ((this.maxIdle == null) || (this.maxIdle < 1)) {
return DEFAULT_MAXIDLE;
} else {
return this.maxTotal;
}
}
public Integer getMaxTotal() {
if ((this.maxTotal == null) || (this.maxTotal < 0)) {
return DEFAULT_MAXTOTAL;
} else {
return this.maxTotal;
}
}
public Boolean getEnable() {
return null == enable ? DEFAULT_ENABLE : this.enable;
}
public String getUrl() {
return StringUtils.isEmpty(this.url) ? DEFAULT_URL : this.url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
if (StringUtils.isEmpty(this._password)) {
this._password = Crypto.plainText(this.password);
}
return this._password;
}
public void setPassword(String password) {
this.password = password;
}
public List<String> getIncludes() {
return null == includes ? DEFAULT_INCLUDES : this.includes;
}
public void setIncludes(List<String> includes) {
this.includes = includes;
}
public List<String> getExcludes() {
return null == excludes ? DEFAULT_EXCLUDES : this.excludes;
}
public void setExcludes(List<String> excludes) {
this.excludes = excludes;
}
public void setEnable(Boolean enable) {
this.enable = enable;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
public void setDictionary(String dictionary) {
this.dictionary = dictionary;
}
public void setMaxTotal(Integer maxTotal) {
this.maxTotal = maxTotal;
}
public void setLogLevel(String logLevel) {
this.logLevel = logLevel;
}
// 无需保存
private transient String _password;
public ExternalDataSource() {
}
public static final Boolean DEFAULT_ENABLE = false;
public static final String DEFAULT_URL = "jdbc:mysql://127.0.0.1:3306/X?autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8";
public static final String DEFAULT_USERNAME = "root";
public static final String DEFAULT_PASSWORD = "password";
public static final String DEFAULT_DRIVERCLASSNAME = "";
public static final String DEFAULT_DICTIONARY = "";
public static final Integer DEFAULT_MAXTOTAL = 100;
public static final Integer DEFAULT_MAXIDLE = 0;
public static final Boolean DEFAULT_STATENABLE = true;
public static final String DEFAULT_STATFILTER = "mergeStat";
public static final List<String> DEFAULT_INCLUDES = new ArrayList<>();
public static final List<String> DEFAULT_EXCLUDES = new ArrayList<>();
public static final Integer DEFAULT_SLOWSQLMILLIS = 2000;
public static final String DEFAULT_LOGLEVEL = "ERROR";
public static final String DEFAULT_TRANSACTIONISOLATION = "read-committed";
public static final Boolean DEFAULT_TESTCONNECTIONONCHECKIN = false;
public static final Boolean DEFAULT_TESTCONNECTIONONCHECKOUT = false;
public static final Integer DEFAULT_MAXIDLETIME = 300;
public static final Boolean DEFAULT_AUTOCOMMIT = false;
public static final Boolean DEFAULT_TRACESQLENABLE = false;
public static final String DEFAULT_SCHEMA = "X";
public static ExternalDataSource defaultInstance() {
ExternalDataSource o = new ExternalDataSource();
o.enable = DEFAULT_ENABLE;
o.url = DEFAULT_URL;
o.username = DEFAULT_USERNAME;
o.password = DEFAULT_PASSWORD;
o.driverClassName = DEFAULT_DRIVERCLASSNAME;
o.dictionary = DEFAULT_DICTIONARY;
o.maxTotal = DEFAULT_MAXTOTAL;
o.maxIdle = DEFAULT_MAXIDLE;
o.statEnable = DEFAULT_STATENABLE;
o.statFilter = DEFAULT_STATFILTER;
o.slowSqlMillis = DEFAULT_SLOWSQLMILLIS;
o.includes = DEFAULT_INCLUDES;
o.excludes = DEFAULT_EXCLUDES;
o.logLevel = DEFAULT_LOGLEVEL;
o.transactionIsolation = DEFAULT_TRANSACTIONISOLATION;
o.testConnectionOnCheckin = DEFAULT_TESTCONNECTIONONCHECKIN;
o.testConnectionOnCheckout = DEFAULT_TESTCONNECTIONONCHECKOUT;
o.maxIdleTime = DEFAULT_MAXIDLETIME;
o.autoCommit = DEFAULT_AUTOCOMMIT;
o.traceSqlEnable = DEFAULT_TRACESQLENABLE;
return o;
}
@FieldDescribe("是否启用,如果启用多个数据库,那么必须是相同类型的,不能混用,且用户名密码必须一致.")
private Boolean enable;
@FieldDescribe("jdbc连接地址.")
private String url;
@FieldDescribe("数据库jdbc连接用户名.")
private String username;
@FieldDescribe("数据库jdbc连接密码.")
private String password;
@FieldDescribe("数据库驱动类名.")
private String driverClassName;
@FieldDescribe("方言类.")
private String dictionary;
@FieldDescribe("最大使用连接数.")
private Integer maxTotal;
@FieldDescribe("最大空闲连接数.")
private Integer maxIdle;
@FieldDescribe("启用统计,默认启用.")
private Boolean statEnable;
@FieldDescribe("统计方式配置,默认mergeStat.")
private String statFilter;
@FieldDescribe("执行缓慢sql毫秒数,默认2000毫秒,执行缓慢的sql将被单独记录.")
private Integer slowSqlMillis;
@FieldDescribe("设置此数据库存储的类,默认情况下存储所有类型,如果需要对每个类进行单独的控制以达到高性能,可以将不同的类存储到不同的节点上提高性能.可以使用通配符*.")
private List<String> includes;
@FieldDescribe("在此节点上不存储的类,和includes一起设置实际存储的类,可以使用通配符*.")
private List<String> excludes;
@FieldDescribe("默认日志级别,FATAL, ERROR, WARN, INFO, TRACE. 完整的配置为DefaultLevel=WARN, Tool=TRACE, Enhance=TRACE, METADATA=TRACE, Runtime=TRACE, Query=TRACE, DataCache=TRACE, JDBC=TRACE, SQL=TRACE.")
private String logLevel = DEFAULT_LOGLEVEL;
@FieldDescribe("事务隔离级别:default,none,read-uncommitted,read-committed,repeatable-read,serializable.默认使用default(数据库设置的事务级别).")
private String transactionIsolation;
@FieldDescribe("测试入池连接,默认false.")
private Boolean testConnectionOnCheckin;
@FieldDescribe("测试出池连接,默认false.")
private Boolean testConnectionOnCheckout;
@FieldDescribe("空闲阈值,默认300秒.")
private Integer maxIdleTime;
@FieldDescribe("自动提交,默认为false.")
private Boolean autoCommit = DEFAULT_AUTOCOMMIT;
@FieldDescribe("启用sql跟踪.")
private Boolean traceSqlEnable = DEFAULT_TRACESQLENABLE;
@FieldDescribe("模式.")
private String schema = DEFAULT_SCHEMA;
public Boolean getTraceSqlEnable() {
return (null == this.traceSqlEnable) ? DEFAULT_TRACESQLENABLE : this.traceSqlEnable;
}
public Boolean getAutoCommit() {
return (null == this.autoCommit) ? DEFAULT_AUTOCOMMIT : this.autoCommit;
}
public Integer getMaxIdleTime() {
return maxIdleTime == null ? DEFAULT_MAXIDLETIME : this.maxIdleTime;
}
public Boolean getTestConnectionOnCheckin() {
return this.testConnectionOnCheckin == null ? DEFAULT_TESTCONNECTIONONCHECKIN : this.testConnectionOnCheckin;
}
public Boolean getTestConnectionOnCheckout() {
return this.testConnectionOnCheckout == null ? DEFAULT_TESTCONNECTIONONCHECKOUT : this.testConnectionOnCheckout;
}
public String getTransactionIsolation() {
return StringUtils.isEmpty(this.transactionIsolation) ? DEFAULT_TRANSACTIONISOLATION
: this.transactionIsolation;
}
public String getLogLevel() {
return StringUtils.isEmpty(this.logLevel) ? DEFAULT_LOGLEVEL : this.logLevel;
}
public String getDriverClassName() throws Exception {
return StringUtils.isEmpty(this.driverClassName) ? SlicePropertiesBuilder.driverClassNameOfUrl(this.url)
: this.driverClassName;
}
public String getDictionary() throws Exception {
return StringUtils.isEmpty(this.dictionary) ? SlicePropertiesBuilder.dictionaryOfUrl(this.url)
: this.dictionary;
}
public Integer getSlowSqlMillis() {
return (null == this.slowSqlMillis || this.slowSqlMillis < 1) ? DEFAULT_SLOWSQLMILLIS : this.slowSqlMillis;
}
public String getStatFilter() {
return StringUtils.isEmpty(this.statFilter) ? DEFAULT_STATFILTER : this.statFilter;
}
public Boolean getStatEnable() {
return null == statEnable ? DEFAULT_STATENABLE : this.statEnable;
}
public Integer getMaxIdle() {
if ((this.maxIdle == null) || (this.maxIdle < 1)) {
return DEFAULT_MAXIDLE;
} else {
return this.maxTotal;
}
}
public Integer getMaxTotal() {
if ((this.maxTotal == null) || (this.maxTotal < 0)) {
return DEFAULT_MAXTOTAL;
} else {
return this.maxTotal;
}
}
public Boolean getEnable() {
return null == enable ? DEFAULT_ENABLE : this.enable;
}
public String getUrl() {
return StringUtils.isEmpty(this.url) ? DEFAULT_URL : this.url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
if (StringUtils.isEmpty(this._password)) {
this._password = Crypto.plainText(this.password);
}
return this._password;
}
public void setPassword(String password) {
this.password = password;
}
public List<String> getIncludes() {
return null == includes ? DEFAULT_INCLUDES : this.includes;
}
public void setIncludes(List<String> includes) {
this.includes = includes;
}
public List<String> getExcludes() {
return null == excludes ? DEFAULT_EXCLUDES : this.excludes;
}
public void setExcludes(List<String> excludes) {
this.excludes = excludes;
}
public void setEnable(Boolean enable) {
this.enable = enable;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
public void setDictionary(String dictionary) {
this.dictionary = dictionary;
}
public void setMaxTotal(Integer maxTotal) {
this.maxTotal = maxTotal;
}
public void setLogLevel(String logLevel) {
this.logLevel = logLevel;
}
public String getSchema() {
return StringUtils.isBlank(this.schema) ? DEFAULT_SCHEMA : this.schema;
}
}
......@@ -99,14 +99,23 @@ public class ExternalDataSources extends CopyOnWriteArrayList<ExternalDataSource
return "DefaultLevel=WARN, Tool=WARN, Enhance=WARN, METADATA=WARN, Runtime=WARN, Query=WARN, DataCache=WARN, JDBC=ERROR, SQL=WARN";
}
public String dictionary() throws Exception {
for (ExternalDataSource o : this) {
if (BooleanUtils.isTrue(o.getEnable())) {
return o.getDictionary();
}
}
throw new Exception("dictionary error.");
}
public String dictionary() throws Exception {
for (ExternalDataSource o : this) {
if (BooleanUtils.isTrue(o.getEnable())) {
return o.getDictionary();
}
}
throw new IllegalStateException("get dictionary error.");
}
public String schema() throws Exception {
for (ExternalDataSource o : this) {
if (BooleanUtils.isTrue(o.getEnable())) {
return o.getSchema();
}
}
throw new IllegalStateException("get schema error.");
}
public boolean hasSchema() throws Exception {
for (ExternalDataSource o : this) {
......
......@@ -14,6 +14,7 @@ import com.x.base.core.project.annotation.ModuleType;
"com.x.query.core.entity.neural.OutValue", "com.x.query.core.entity.neural.Model",
"com.x.query.core.entity.schema.*", "com.x.query.core.entity.index.State",
"com.x.processplatform.core.entity.content.Review",
"com.x.processplatform.core.entity.content.Task",
"com.x.processplatform.core.entity.element.Process",
"com.x.processplatform.core.entity.element.Application",
"com.x.query.core.entity.ImportModel", "com.x.processplatform.core.entity.content.Work",
......
......@@ -7,18 +7,19 @@ import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopFieldCollector;
import org.apache.lucene.store.Directory;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
......@@ -53,6 +54,7 @@ import com.x.query.assemble.surface.Business;
import com.x.query.assemble.surface.ThisApplication;
import com.x.query.core.express.assemble.surface.jaxrs.index.ActionExportWi;
import com.x.query.core.express.index.Indexs;
import com.x.query.core.express.index.WoField;
import io.swagger.v3.oas.annotations.media.Schema;
......@@ -70,16 +72,21 @@ class ActionExport extends BaseAction {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
String category = wi.getCategory();
String key = wi.getKey();
List<String> readers = new ArrayList<>();
Set<String> readers = new TreeSet<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
String person = business.index().who(effectivePerson, wi.getPerson());
readers = business.index().determineReaders(person, category, key);
wi.getDirectoryList().stream().forEach(o -> {
try {
readers.addAll(business.index().determineReaders(person, o.getCategory(), o.getKey()));
} catch (Exception e) {
LOGGER.error(e);
}
});
}
List<String> categories = this.categories(wi.getDirectoryList());
Optional<Query> searchQuery = searchQuery(wi.getQuery(), new HanLPAnalyzer());
Optional<Query> readersQuery = Indexs.readersQuery(readers);
List<Query> filterQueries = Indexs.filterQueries(wi.getFilterList());
......@@ -89,14 +96,13 @@ class ActionExport extends BaseAction {
filterQueries.stream().forEach(o -> builder.add(o, BooleanClause.Occur.MUST));
Query query = builder.build();
LOGGER.debug("index export lucene query:{}.", query::toString);
Optional<Directory> optional = Indexs.directory(category, key, true);
if (optional.isEmpty()) {
throw new ExceptionDirectoryNotExist();
}
try (DirectoryReader reader = DirectoryReader.open(optional.get()); Workbook workbook = new XSSFWorkbook()) {
List<Triple<String, String, String>> outFields = outFields(wi.getFixedFieldList(),
try (MultiReader multiReader = new MultiReader(indexReaders(wi.getDirectoryList()));
Workbook workbook = new XSSFWorkbook()) {
List<Triple<String, String, String>> outFields = outFields(
this.getFixedFieldList(categories),
wi.getFixedFieldList(),
wi.getDynamicFieldList());
IndexSearcher searcher = new IndexSearcher(reader);
IndexSearcher searcher = new IndexSearcher(multiReader);
TopFieldCollector topFieldCollector = TopFieldCollector.create(sort(wi.getSort()),
Config.query().index().getSearchMaxHits(), Config.query().index().getSearchMaxHits());
searcher.search(query, topFieldCollector);
......@@ -138,11 +144,11 @@ class ActionExport extends BaseAction {
return result;
}
private List<Triple<String, String, String>> outFields(List<String> fixedFieldList,
private List<Triple<String, String, String>> outFields(List<WoField> woFields, List<String> fixedFieldList,
List<String> dynamicFieldList) {
List<Triple<String, String, String>> list = new ArrayList<>();
if (ListTools.isEmpty(fixedFieldList) && ListTools.isEmpty(dynamicFieldList)) {
list.addAll(getFixedFieldList(Indexs.CATEGORY_PROCESSPLATFORM).stream()
list.addAll(woFields.stream()
.map(o -> Triple.of(o.getField(), o.getName(), o.getFieldType())).collect(Collectors.toList()));
} else {
if (!ListTools.isEmpty(fixedFieldList)) {
......@@ -182,7 +188,7 @@ class ActionExport extends BaseAction {
cell.setCellStyle(cellStyle);
});
// auto row size
// row.setHeight((short) 0);
row.setHeight((short) 0);
return sheet;
}
......@@ -190,15 +196,17 @@ class ActionExport extends BaseAction {
final Row row = param.third().createRow(param.third().getLastRowNum() + 1);
Streams.mapWithIndex(param.first().stream(), Pair::of)
.map(o -> Quintuple.of(o.first().first(), o.first().second(), o.first().third(), o.second(),
param.second().getField(o.first().first())))
param.second().getFields(o.first().first())))
.filter(o -> !Objects.isNull(o.fifth())).forEach(o -> {
Object value = Indexs.indexableFieldValue(o.fifth(), o.third());
Cell cell = row.createCell(o.fourth().intValue());
cell.setCellValue(Objects.toString(value, ""));
if ((null != value) && (Date.class.isAssignableFrom(value.getClass()))) {
cell.setCellValue(DateTools.format((Date) value));
} else {
cell.setCellValue(Objects.toString(value, ""));
}
cell.setCellStyle(param.fourth());
});
// auto row size
// row.setHeight((short) 0);
};
@Schema(name = "com.x.custom.index.assemble.control.jaxrs.search.ActionExport$Wo")
......
......@@ -11,7 +11,6 @@ import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.NameValuePair;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.gson.GsonPropertyObject;
......@@ -60,8 +59,8 @@ class ActionListDirectory extends BaseAction {
private Wo processPlatform(Business business) throws Exception {
EntityManagerContainer emc = business.entityManagerContainer();
List<Application> os = emc.fetchAll(Application.class, APPLICATIONATTRIBUTES);
List<NameValuePair> keys = os.stream().map(o -> new NameValuePair(o.getName(), o.getId()))
.sorted(Comparator.nullsLast(Comparator.comparing(NameValuePair::getName))).collect(
List<WoKey> keys = os.stream().map(o -> new WoKey(o.getName(), o.getId()))
.sorted(Comparator.nullsLast(Comparator.comparing(WoKey::getName))).collect(
ArrayList::new, List::add,
List::addAll);
Wo wo = new Wo();
......@@ -73,8 +72,8 @@ class ActionListDirectory extends BaseAction {
private Wo cms(Business business) throws Exception {
EntityManagerContainer emc = business.entityManagerContainer();
List<AppInfo> os = emc.fetchAll(AppInfo.class, APPINFOATTRIBUTES);
List<NameValuePair> keys = os.stream().map(o -> new NameValuePair(o.getAppName(), o.getId()))
.sorted(Comparator.nullsLast(Comparator.comparing(NameValuePair::getName))).collect(
List<WoKey> keys = os.stream().map(o -> new WoKey(o.getAppName(), o.getId()))
.sorted(Comparator.nullsLast(Comparator.comparing(WoKey::getName))).collect(
ArrayList::new, List::add,
List::addAll);
Wo wo = new Wo();
......@@ -83,7 +82,7 @@ class ActionListDirectory extends BaseAction {
return wo;
}
@Schema(name = "com.x.custom.index.assemble.control.jaxrs.index.ActionPost$Wo")
@Schema(name = "com.x.query.assemble.surface.jaxrs.index.ActionListDirectory$Wo")
public class Wo extends GsonPropertyObject {
@FieldDescribe("分类")
......@@ -92,7 +91,7 @@ class ActionListDirectory extends BaseAction {
@FieldDescribe("标识")
@Schema(description = "标识")
private List<NameValuePair> keyList = new ArrayList<>();
private List<WoKey> keyList = new ArrayList<>();
public String getCategory() {
return category;
......@@ -102,14 +101,48 @@ class ActionListDirectory extends BaseAction {
this.category = category;
}
public List<NameValuePair> getKeyList() {
public List<WoKey> getKeyList() {
return keyList;
}
public void setKeyList(List<NameValuePair> keyList) {
public void setKeyList(List<WoKey> keyList) {
this.keyList = keyList;
}
}
@Schema(name = "com.x.query.assemble.surface.jaxrs.index.ActionListDirectory$WoKey")
public class WoKey extends GsonPropertyObject {
public WoKey(String name, String key) {
this.name = name;
this.key = key;
}
@FieldDescribe("名称.")
@Schema(description = "名称.")
private String name;
@FieldDescribe("标识.")
@Schema(description = "标识.")
private String key;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}
}
\ No newline at end of file
package com.x.query.assemble.surface.jaxrs.index;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
......@@ -8,11 +7,11 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.collections4.list.TreeList;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.search.BooleanClause;
......@@ -68,7 +67,7 @@ class ActionPost extends BaseAction {
Integer rows = Indexs.rows(wi.getSize());
Integer start = Indexs.start(wi.getPage(), rows);
List<String> readers = new TreeList<>();
Set<String> readers = new TreeSet<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
String person = business.index().who(effectivePerson, wi.getPerson());
......@@ -81,10 +80,12 @@ class ActionPost extends BaseAction {
});
}
initWo(wo);
List<String> categories = this.categories(wi.getDirectoryList());
initWo(wo, categories);
Optional<Query> searchQuery = searchQuery(wi.getQuery(), new HanLPAnalyzer());
Optional<Query> readersQuery = Indexs.readersQuery(ListTools.trim(readers, true, true));
Optional<Query> readersQuery = Indexs.readersQuery(readers);
List<Query> filterQueries = Indexs.filterQueries(wi.getFilterList());
BooleanQuery.Builder builder = new BooleanQuery.Builder();
Stream.of(searchQuery, readersQuery).filter(Optional::isPresent)
......@@ -92,16 +93,17 @@ class ActionPost extends BaseAction {
filterQueries.stream().forEach(o -> builder.add(o, BooleanClause.Occur.MUST));
Query query = builder.build();
LOGGER.debug("index lucene query:{}.", query::toString);
IndexReader[] indexReaders = this.indexReaders(wi);
IndexReader[] indexReaders = this.indexReaders(wi.getDirectoryList());
if (indexReaders.length == 0) {
return result;
}
try (MultiReader multiReader = new MultiReader(indexReaders)) {
IndexSearcher searcher = new IndexSearcher(multiReader);
wo.setDynamicFieldList(getDynamicFieldList(multiReader));
wo.setDynamicFieldList(getDynamicFieldList(categories, multiReader));
TopFieldCollector topFieldCollector = TopFieldCollector.create(sort(wi.getSort()), 1000, 1000);
List<Pair<String, FirstPassGroupingCollector<BytesRef>>> firstPassGroupingCollectorPairs = Indexs
.adjustFacetField(wi.getFilterList().stream().map(Filter::getField).collect(Collectors.toList()))
List<Pair<String, FirstPassGroupingCollector<BytesRef>>> firstPassGroupingCollectorPairs = this
.adjustFacetField(categories,
wi.getFilterList().stream().map(Filter::getField).collect(Collectors.toList()))
.stream()
.<Pair<String, FirstPassGroupingCollector<BytesRef>>>map(o -> {
try {
......@@ -153,20 +155,8 @@ class ActionPost extends BaseAction {
return result;
}
private void initWo(Wo wo) {
wo.setFixedFieldList(this.getFixedFieldList(Indexs.CATEGORY_PROCESSPLATFORM));
}
private IndexReader[] indexReaders(Wi wi) {
return wi.getDirectoryList().stream().map(o -> Indexs.directory(o.getCategory(), o.getKey(), true))
.filter(Optional::isPresent).map(Optional::get).map(o -> {
try {
return DirectoryReader.open(o);
} catch (IOException e) {
LOGGER.error(e);
}
return null;
}).filter(o -> !Objects.isNull(o)).toArray(s -> new IndexReader[s]);
private void initWo(Wo wo, List<String> categories) {
wo.setFixedFieldList(this.getFixedFieldList(categories));
}
private void writeDocument(IndexSearcher searcher, TopFieldCollector topFieldCollector, int start, int rows, Wo wo,
......@@ -180,8 +170,8 @@ class ActionPost extends BaseAction {
try {
org.apache.lucene.document.Document document = searcher.doc(o.doc);
Map<String, Object> map = outFields.stream()
.map(f -> Quadruple.of(Indexs.judgeField(f), document.getField(f)))
.filter(param -> null != param.fourth())
.map(f -> Quadruple.of(Indexs.judgeField(f), document.getFields(f)))
.filter(param -> param.fourth().length > 0)
.map(p -> Pair.of(p.first(), Indexs.indexableFieldValue(p.fourth(), p.third())))
.collect(Collectors.toMap(Pair::first, Pair::second));
wo.getDocumentList().add(map);
......
package com.x.query.assemble.surface.jaxrs.index;
//package com.x.query.assemble.surface.jaxrs.index;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.Collection;
//import java.util.List;
//import java.util.Map;
//import java.util.Objects;
//import java.util.Optional;
//import java.util.stream.Collectors;
//import java.util.stream.Stream;
//
//import org.apache.lucene.index.DirectoryReader;
//import org.apache.lucene.search.BooleanClause;
//import org.apache.lucene.search.BooleanQuery;
//import org.apache.lucene.search.IndexSearcher;
//import org.apache.lucene.search.MultiCollector;
//import org.apache.lucene.search.Query;
//import org.apache.lucene.search.ScoreDoc;
//import org.apache.lucene.search.TopDocs;
//import org.apache.lucene.search.TopFieldCollector;
//import org.apache.lucene.search.grouping.FirstPassGroupingCollector;
//import org.apache.lucene.search.grouping.SearchGroup;
//import org.apache.lucene.search.grouping.TermGroupSelector;
//import org.apache.lucene.search.grouping.TopGroupsCollector;
//import org.apache.lucene.store.Directory;
//import org.apache.lucene.util.BytesRef;
//
//import com.google.gson.JsonElement;
//import com.hankcs.lucene.HanLPAnalyzer;
//import com.x.base.core.container.EntityManagerContainer;
//import com.x.base.core.container.factory.EntityManagerContainerFactory;
//import com.x.base.core.project.bean.tuple.Pair;
//import com.x.base.core.project.bean.tuple.Quadruple;
//import com.x.base.core.project.config.Config;
//import com.x.base.core.project.http.ActionResult;
//import com.x.base.core.project.http.EffectivePerson;
//import com.x.base.core.project.logger.Logger;
//import com.x.base.core.project.logger.LoggerFactory;
//import com.x.base.core.project.tools.ListTools;
//import com.x.query.assemble.surface.Business;
//import com.x.query.core.express.assemble.surface.jaxrs.index.ActionPostWi;
//import com.x.query.core.express.assemble.surface.jaxrs.index.ActionPostWo;
//import com.x.query.core.express.index.Facets;
//import com.x.query.core.express.index.Filter;
//import com.x.query.core.express.index.Indexs;
//import com.x.query.core.express.index.WoField;
//
//import io.swagger.v3.oas.annotations.media.Schema;
//
//class ActionPost extends BaseAction {
//
// private static final Logger LOGGER = LoggerFactory.getLogger(ActionPost.class);
//
// ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
//
// LOGGER.info("execute:{}.", effectivePerson::getDistinguishedName);
//
// ActionResult<Wo> result = new ActionResult<>();
// Wo wo = new Wo();
// result.setData(wo);
//
// Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
//
// String category = wi.getCategory();
// String key = wi.getKey();
// Integer rows = Indexs.rows(wi.getSize());
// Integer start = Indexs.start(wi.getPage(), rows);
//
// List<String> readers = new ArrayList<>();
// try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
// Business business = new Business(emc);
// String person = business.index().who(effectivePerson, wi.getPerson());
// readers = business.index().determineReaders(person, category, key);
// }
//
// initWo(wo, wi);
//
// Optional<Query> searchQuery = searchQuery(wi.getQuery(), new HanLPAnalyzer());
// Optional<Query> readersQuery = Indexs.readersQuery(readers);
// List<Query> filterQueries = Indexs.filterQueries(wi.getFilterList());
// BooleanQuery.Builder builder = new BooleanQuery.Builder();
// Stream.of(searchQuery, readersQuery).filter(Optional::isPresent)
// .forEach(o -> builder.add(o.get(), BooleanClause.Occur.MUST));
// filterQueries.stream().forEach(o -> builder.add(o, BooleanClause.Occur.MUST));
// Query query = builder.build();
// LOGGER.debug("index lucene query:{}.", query::toString);
// Optional<Directory> optional = Indexs.directory(category, key, true);
// if (optional.isEmpty()) {
// throw new ExceptionDirectoryNotExist();
// }
// try (DirectoryReader reader = DirectoryReader.open(optional.get())) {
// wo.setDynamicFieldList(getDynamicFieldList(reader));
// IndexSearcher searcher = new IndexSearcher(reader);
// TopFieldCollector topFieldCollector = TopFieldCollector.create(sort(wi.getSort()), 1000, 1000);
// List<Pair<String, FirstPassGroupingCollector<BytesRef>>> firstPassGroupingCollectorPairs = Indexs
// .adjustFacetField(wi.getFilterList().stream().map(Filter::getField).collect(Collectors.toList()))
// .stream()
// .<Pair<String, FirstPassGroupingCollector<BytesRef>>>map(o -> {
// try {
// return Pair.of(o,
// new FirstPassGroupingCollector<>(new TermGroupSelector(o),
// org.apache.lucene.search.Sort.INDEXORDER,
// Config.query().index().getFacetMaxGroups()));
// } catch (Exception ex) {
// LOGGER.error(ex);
// }
// return null;
// }).filter(o -> !Objects.isNull(o)).collect(Collectors.toList());
// searcher.search(query, MultiCollector.wrap(topFieldCollector, MultiCollector
// .wrap(firstPassGroupingCollectorPairs.stream().map(Pair::second).collect(Collectors.toList()))));
// writeDocument(searcher, topFieldCollector, start, rows, wo, wi.getFixedFieldList(),
// wi.getDynamicFieldList());
// List<Pair<String, TopGroupsCollector<BytesRef>>> topGroupsCollectorPairs = firstPassGroupingCollectorPairs
// .stream().<Pair<String, Optional<Collection<SearchGroup<BytesRef>>>>>map(param -> {
// Collection<SearchGroup<BytesRef>> topGroups = null;
// try {
// topGroups = param.second().getTopGroups(0);
// } catch (Exception e) {
// LOGGER.error(e);
// }
// if (Objects.isNull(topGroups)) {
// return Pair.of(param.first(), Optional.empty());
// } else {
// return Pair.of(param.first(), Optional.of(topGroups));
// }
// }).filter(o -> o.second().isPresent())
// .<Pair<String, TopGroupsCollector<BytesRef>>>map(param -> {
// try {
// return Pair.of(param.first(),
// new TopGroupsCollector<>(new TermGroupSelector(param.first()), param.second().get(),
// org.apache.lucene.search.Sort.INDEXORDER,
// org.apache.lucene.search.Sort.INDEXORDER,
// Config.query().index().getSearchMaxHits(), false));
// } catch (Exception e) {
// LOGGER.error(e);
// }
// return null;
// }).filter(o -> !Objects.isNull(o)).collect(Collectors.toList());
// if (!topGroupsCollectorPairs.isEmpty()) {
// searcher.search(query, MultiCollector
// .wrap(topGroupsCollectorPairs.stream().map(Pair::second).collect(Collectors.toList())));
// wo.setFacetList(Facets.topGroupsCollector(topGroupsCollectorPairs));
// }
// }
// return result;
// }
//
// private void initWo(Wo wo, Wi wi) {
// wo.setFixedFieldList(this.getFixedFieldList(Indexs.CATEGORY_PROCESSPLATFORM));
// }
//
// private void writeDocument(IndexSearcher searcher, TopFieldCollector topFieldCollector, int start, int rows, Wo wo,
// List<String> fixedFieldList, List<String> dynamicFieldList) {
// List<String> outFields = outFields(wo, fixedFieldList, dynamicFieldList);
// TopDocs topDocs = topFieldCollector.topDocs(start, rows);
// wo.setCount(topDocs.totalHits.value);
// ScoreDoc[] scoreDocs = topDocs.scoreDocs;
// if (null != scoreDocs) {
// Arrays.stream(scoreDocs).forEach(o -> {
// try {
// org.apache.lucene.document.Document document = searcher.doc(o.doc);
// Map<String, Object> map = outFields.stream()
// .map(f -> Quadruple.of(Indexs.judgeField(f), document.getField(f)))
// .filter(param -> null != param.fourth())
// .map(p -> Pair.of(p.first(), Indexs.indexableFieldValue(p.fourth(), p.third())))
// .collect(Collectors.toMap(Pair::first, Pair::second));
// wo.getDocumentList().add(map);
// } catch (Exception e) {
// LOGGER.error(e);
// }
// });
// }
// }
//
// private List<String> outFields(Wo wo, List<String> fixedFieldList, List<String> dynamicFieldList) {
// List<String> list = new ArrayList<>();
// list.add(Indexs.FIELD_ID);
// if (ListTools.isEmpty(fixedFieldList) && ListTools.isEmpty(dynamicFieldList)) {
// list.addAll(wo.getFixedFieldList().stream().map(WoField::getField).collect(Collectors.toList()));
// } else {
// list.addAll(fixedFieldList);
// list.addAll(dynamicFieldList);
// }
// return list;
// }
//
// @Schema(name = "com.x.custom.index.assemble.control.jaxrs.index.ActionPost$Wo")
// public class Wo extends ActionPostWo {
//
// private static final long serialVersionUID = 3751674531291729956L;
//
// }
//
// @Schema(name = "com.x.custom.index.assemble.control.jaxrs.index.ActionPost$Wi")
// public class Wi extends ActionPostWi {
//
// private static final long serialVersionUID = -4646809016933808952L;
//
// }
//
//}
\ No newline at end of file
......@@ -102,31 +102,31 @@ class ActionPost extends BaseAction {
org.apache.lucene.document.Document document = reader.document(scoreDoc.doc);
ActionPostWo.WoMoreLikeThis woMoreLikeThis = new ActionPostWo.WoMoreLikeThis();
woMoreLikeThis.setTitle(
Indexs.<String>indexableFieldValue(document.getField(Indexs.FIELD_TITLE),
Indexs.<String>indexableFieldValue(document.getFields(Indexs.FIELD_TITLE),
Indexs.FIELD_TYPE_STRING));
woMoreLikeThis.setFlag(
Indexs.<String>indexableFieldValue(document.getField(Indexs.FIELD_ID),
Indexs.<String>indexableFieldValue(document.getFields(Indexs.FIELD_ID),
Indexs.FIELD_TYPE_STRING));
woMoreLikeThis.setCategory(
Indexs.<String>indexableFieldValue(document.getField(Indexs.FIELD_CATEGORY),
Indexs.<String>indexableFieldValue(document.getFields(Indexs.FIELD_CATEGORY),
Indexs.FIELD_TYPE_STRING));
woMoreLikeThis.setType(
Indexs.<String>indexableFieldValue(document.getField(Indexs.FIELD_TYPE),
Indexs.<String>indexableFieldValue(document.getFields(Indexs.FIELD_TYPE),
Indexs.FIELD_TYPE_STRING));
woMoreLikeThis.setKey(
Indexs.<String>indexableFieldValue(document.getField(Indexs.FIELD_KEY),
Indexs.<String>indexableFieldValue(document.getFields(Indexs.FIELD_KEY),
Indexs.FIELD_TYPE_STRING));
woMoreLikeThis.setCreateTime(
Indexs.<Date>indexableFieldValue(document.getField(Indexs.FIELD_CREATETIME),
Indexs.<Date>indexableFieldValue(document.getFields(Indexs.FIELD_CREATETIME),
Indexs.FIELD_TYPE_DATE));
woMoreLikeThis.setUpdateTime(
Indexs.<Date>indexableFieldValue(document.getField(Indexs.FIELD_UPDATETIME),
Indexs.<Date>indexableFieldValue(document.getFields(Indexs.FIELD_UPDATETIME),
Indexs.FIELD_TYPE_DATE));
woMoreLikeThis.setCreatorPerson(Indexs.<String>indexableFieldValue(
document.getField(Indexs.FIELD_CREATORPERSON),
document.getFields(Indexs.FIELD_CREATORPERSON),
Indexs.FIELD_TYPE_STRING));
woMoreLikeThis.setCreatorUnit(Indexs.<String>indexableFieldValue(
document.getField(Indexs.FIELD_CREATORUNIT),
document.getFields(Indexs.FIELD_CREATORUNIT),
Indexs.FIELD_TYPE_STRING));
woMoreLikeThis.setKey(document.get(Indexs.FIELD_KEY));
woMoreLikeThis.setScore(scoreDoc.score);
......
......@@ -6,7 +6,6 @@ import java.util.Optional;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
......
......@@ -22,7 +22,6 @@ import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
......
......@@ -99,8 +99,9 @@ class ActionPost extends BaseAction {
final int facetMaxGroups = Config.query().index().getFacetMaxGroups();
final int searchMaxHits = Config.query().index().getSearchMaxHits();
TopScoreDocCollector topScoreDocCollector = TopScoreDocCollector.create(searchMaxHits, Integer.MAX_VALUE);
List<Pair<String, FirstPassGroupingCollector<BytesRef>>> firstPassGroupingCollectorPairs = Indexs
.adjustFacetField(wi.getFilterList().stream().map(Filter::getField).collect(Collectors.toList()))
List<Pair<String, FirstPassGroupingCollector<BytesRef>>> firstPassGroupingCollectorPairs = this
.adjustFacetField(
wi.getFilterList().stream().map(Filter::getField).collect(Collectors.toList()))
.stream()
.<Pair<String, FirstPassGroupingCollector<BytesRef>>>map(
o -> Pair.of(o,
......
package com.x.query.assemble.surface.jaxrs.search;
import java.util.Optional;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapString;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.query.core.express.index.Indexs;
class ActionTest extends BaseAction {
......
package com.x.query.assemble.surface.jaxrs.search;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
......@@ -69,4 +70,26 @@ abstract class BaseAction extends StandardJaxrsAction {
return Optional.of(builder.build());
}
protected List<String> adjustFacetField(List<String> filters) {
List<String> list = FACET_FIELDS.stream().filter(o -> (!filters.contains(o))).collect(Collectors.toList());
if (list.contains(Indexs.FIELD_PROCESSNAME)) {
list.removeAll(Arrays.asList(Indexs.FIELD_APPLICATIONNAME, Indexs.FIELD_PROCESSNAME,
Indexs.FIELD_APPNAME, Indexs.FIELD_CATEGORYNAME));
}
if (list.contains(Indexs.FIELD_APPLICATIONNAME)) {
list.removeAll(Arrays.asList(Indexs.FIELD_APPLICATIONNAME, Indexs.FIELD_APPNAME,
Indexs.FIELD_CATEGORYNAME));
}
if (list.contains(Indexs.FIELD_CATEGORYNAME)) {
list.removeAll(Arrays.asList(Indexs.FIELD_APPNAME, Indexs.FIELD_CATEGORYNAME,
Indexs.FIELD_APPLICATIONNAME, Indexs.FIELD_PROCESSNAME));
}
if (list.contains(Indexs.FIELD_APPNAME)) {
list.removeAll(Arrays.asList(Indexs.FIELD_APPNAME, Indexs.FIELD_APPLICATIONNAME,
Indexs.FIELD_PROCESSNAME));
}
list.remove(Indexs.FIELD_COMPLETED);
return list;
}
}
\ No newline at end of file
......@@ -13,7 +13,6 @@ import javax.script.Bindings;
import javax.script.CompiledScript;
import javax.script.ScriptContext;
import com.x.base.core.project.tools.StringTools;
import org.apache.commons.collections4.list.TreeList;
import org.apache.commons.lang3.StringUtils;
......
......@@ -2,10 +2,13 @@ package com.x.query.assemble.surface.jaxrs.view;
import java.io.ByteArrayOutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
......
......@@ -5,6 +5,7 @@ import java.util.List;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.query.core.express.index.Directory;
import com.x.query.core.express.index.Filter;
import com.x.query.core.express.index.Sort;
......@@ -14,13 +15,9 @@ public class ActionExportWi extends GsonPropertyObject {
private static final long serialVersionUID = 1360655000630283661L;
@FieldDescribe("分类.")
@Schema(description = "分类.")
private String category;
@FieldDescribe("标识.")
@Schema(description = "标识.")
private String key;
@FieldDescribe("检索目录.")
@Schema(description = "检索目录.")
private List<Directory> directoryList = new ArrayList<>();
@FieldDescribe("搜索内容.")
@Schema(description = "搜索内容.")
......@@ -54,6 +51,14 @@ public class ActionExportWi extends GsonPropertyObject {
@Schema(description = "排序字段.")
Sort sort;
public List<Directory> getDirectoryList() {
return directoryList;
}
public void setDirectoryList(List<Directory> directoryList) {
this.directoryList = directoryList;
}
public Sort getSort() {
return sort;
}
......@@ -102,22 +107,6 @@ public class ActionExportWi extends GsonPropertyObject {
this.size = size;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getPerson() {
return person;
}
......
......@@ -5,6 +5,7 @@ import java.util.List;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.query.core.express.index.Directory;
import com.x.query.core.express.index.Filter;
import com.x.query.core.express.index.Sort;
......@@ -16,7 +17,7 @@ public class ActionPostWi extends GsonPropertyObject {
@FieldDescribe("检索目录.")
@Schema(description = "检索目录.")
private List<WiDirectory> directoryList = new ArrayList<>();
private List<Directory> directoryList = new ArrayList<>();
@FieldDescribe("搜索内容.")
@Schema(description = "搜索内容.")
......@@ -98,11 +99,11 @@ public class ActionPostWi extends GsonPropertyObject {
this.size = size;
}
public List<WiDirectory> getDirectoryList() {
public List<Directory> getDirectoryList() {
return directoryList;
}
public void setDirectoryList(List<WiDirectory> directoryList) {
public void setDirectoryList(List<Directory> directoryList) {
this.directoryList = directoryList;
}
......@@ -122,33 +123,4 @@ public class ActionPostWi extends GsonPropertyObject {
this.filterList = filterList;
}
@Schema(name = "com.x.query.core.express.assemble.surface.jaxrs.index.ActionPostWi$WiDirectory")
public static class WiDirectory {
@FieldDescribe("分类.")
@Schema(description = "分类.")
private String category;
@FieldDescribe("标识.")
@Schema(description = "标识.")
private String key;
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}
}
package com.x.query.core.express.index;
import com.x.base.core.project.annotation.FieldDescribe;
import io.swagger.v3.oas.annotations.media.Schema;
@Schema(name = "com.x.query.core.express.index$Directory")
public class Directory {
@FieldDescribe("分类.")
@Schema(description = "分类.")
private String category;
@FieldDescribe("标识.")
@Schema(description = "标识.")
private String key;
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}
\ No newline at end of file
......@@ -9,46 +9,46 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(name = "com.x.query.core.express.index.Filter")
public class Filter extends GsonPropertyObject {
private static final long serialVersionUID = 8404002412785606829L;
private static final long serialVersionUID = 8404002412785606829L;
String field;
String field;
List<String> valueList;
List<String> valueList;
String start;
String min;
String end;
String max;
public String getField() {
return field;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public void setField(String field) {
this.field = field;
}
public List<String> getValueList() {
return valueList;
}
public List<String> getValueList() {
return valueList;
}
public void setValueList(List<String> valueList) {
this.valueList = valueList;
}
public void setValueList(List<String> valueList) {
this.valueList = valueList;
}
public String getStart() {
return start;
}
public String getMin() {
return min;
}
public void setStart(String start) {
this.start = start;
}
public void setMin(String min) {
this.min = min;
}
public String getEnd() {
return end;
}
public String getMax() {
return max;
}
public void setEnd(String end) {
this.end = end;
}
public void setMax(String max) {
this.max = max;
}
}
......@@ -8,16 +8,20 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.RemoteIterator;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
......@@ -33,6 +37,7 @@ import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.Query;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DateTools;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.NumberTools;
......@@ -96,10 +101,13 @@ public class Indexs {
public static final String FIELD_HIGHLIGHTING = "highlighting";
public static final String READERS_SYMBOL_ALL = "ALL";
public static final String BOOLEAN_TRUE_STRING_VALUE = "true";
public static final String BOOLEAN_FALSE_STRING_VALUE = "false";
private static final List<String> FACET_FIELDS = Stream.<String>of(FIELD_CATEGORY,
FIELD_CREATETIMEMONTH, FIELD_UPDATETIMEMONTH, FIELD_APPLICATIONNAME,
FIELD_PROCESSNAME, FIELD_APPNAME, FIELD_CATEGORYNAME,
FIELD_CREATORPERSON, FIELD_CREATORUNIT)
FIELD_CREATORPERSON, FIELD_CREATORUNIT, FIELD_COMPLETED)
.collect(Collectors.toUnmodifiableList());
private static final List<String> FIXED_DATE_FIELDS = Stream
......@@ -125,6 +133,37 @@ public class Indexs {
public static final String PREFIX_FIELD_DATA_DATE = PREFIX_FIELD_DATA + FIELD_TYPE_DATE + "_";
public static final String PREFIX_FIELD_DATA_DATES = PREFIX_FIELD_DATA + FIELD_TYPE_DATES + "_";
public static final String PREFIX_FIELD_PROCESSPLATFORM = "processPlatform_";
public static final String FIELD_ROCESSPLATFORM_TASKPERSONNAMES = "taskPersonNames";
public static final String FIELD_ROCESSPLATFORM_PRETASKPERSONNAMES = "preTaskPersonNames";
public static final String PREFIX_FIELD_PROCESSPLATFORM_STRING = PREFIX_FIELD_PROCESSPLATFORM + FIELD_TYPE_STRING
+ "_";
public static final String PREFIX_FIELD_PROCESSPLATFORM_STRINGS = PREFIX_FIELD_PROCESSPLATFORM + FIELD_TYPE_STRINGS
+ "_";
public static final String PREFIX_FIELD_PROCESSPLATFORM_BOOLEAN = PREFIX_FIELD_PROCESSPLATFORM + FIELD_TYPE_BOOLEAN
+ "_";
public static final String PREFIX_FIELD_PROCESSPLATFORM_BOOLEANS = PREFIX_FIELD_PROCESSPLATFORM
+ FIELD_TYPE_BOOLEANS + "_";
public static final String PREFIX_FIELD_PROCESSPLATFORM_NUMBER = PREFIX_FIELD_PROCESSPLATFORM + FIELD_TYPE_NUMBER
+ "_";
public static final String PREFIX_FIELD_PROCESSPLATFORM_NUMBERS = PREFIX_FIELD_PROCESSPLATFORM + FIELD_TYPE_NUMBERS
+ "_";
public static final String PREFIX_FIELD_PROCESSPLATFORM_DATE = PREFIX_FIELD_PROCESSPLATFORM + FIELD_TYPE_DATE + "_";
public static final String PREFIX_FIELD_PROCESSPLATFORM_DATES = PREFIX_FIELD_PROCESSPLATFORM + FIELD_TYPE_DATES
+ "_";
public static final String PREFIX_FIELD_CMS = "cms_";
public static final String PREFIX_FIELD_CMS_STRING = PREFIX_FIELD_CMS + FIELD_TYPE_STRING + "_";
public static final String PREFIX_FIELD_CMS_STRINGS = PREFIX_FIELD_CMS + FIELD_TYPE_STRINGS + "_";
public static final String PREFIX_FIELD_CMS_BOOLEAN = PREFIX_FIELD_CMS + FIELD_TYPE_BOOLEAN + "_";
public static final String PREFIX_FIELD_CMS_BOOLEANS = PREFIX_FIELD_CMS + FIELD_TYPE_BOOLEANS + "_";
public static final String PREFIX_FIELD_CMS_NUMBER = PREFIX_FIELD_CMS + FIELD_TYPE_NUMBER + "_";
public static final String PREFIX_FIELD_CMS_NUMBERS = PREFIX_FIELD_CMS + FIELD_TYPE_NUMBERS + "_";
public static final String PREFIX_FIELD_CMS_DATE = PREFIX_FIELD_CMS + FIELD_TYPE_DATE + "_";
public static final String PREFIX_FIELD_CMS_DATES = PREFIX_FIELD_CMS + FIELD_TYPE_DATES + "_";
private static final String[] QUERY_IGNORES = new String[] { "[", "]", "*", "?" };
private static final String[] QUERY_IGNOREREPLACES = new String[] { "", "", "", "" };
......@@ -308,8 +347,8 @@ public class Indexs {
return list;
}
public static Optional<org.apache.lucene.search.Query> readersQuery(List<String> readers) {
if (ListTools.isEmpty(readers)) {
public static Optional<org.apache.lucene.search.Query> readersQuery(Collection<String> readers) {
if ((null == readers) || readers.isEmpty()) {
return Optional.empty();
}
BooleanQuery.Builder builder = new BooleanQuery.Builder();
......@@ -323,19 +362,39 @@ public class Indexs {
if (ListTools.isEmpty(filters)) {
return list;
}
List<Filter> fields = filters.stream().filter(o -> FACET_FIELDS.contains(o.getField()))
.collect(Collectors.toList());
if (ListTools.isEmpty(fields)) {
return list;
}
fields.stream().map(Indexs::fitlerQuery).filter(Optional::isPresent).forEach(o -> list.add(o.get()));
filters.stream().map(Indexs::fitlerQuery).filter(Optional::isPresent).forEach(o -> list.add(o.get()));
return list;
}
private static Optional<org.apache.lucene.search.Query> fitlerQuery(Filter filter) {
if (ListTools.isEmpty(filter.getValueList())) {
if (ListTools.isEmpty(filter.getValueList()) && StringUtils.isEmpty(filter.getMin())
&& StringUtils.isEmpty(filter.getMax())) {
return Optional.empty();
}
if (filter.getField().startsWith(PREFIX_FIELD_DATA_DATE)) {
if (!(StringUtils.isEmpty(filter.getMin()) && StringUtils.isEmpty(filter.getMax()))) {
return Optional
.of(LongPoint.newRangeQuery(filter.getField(), stringOfDateToLongElseMin(filter.getMin()),
stringOfDateToLongElseMax(filter.getMax())));
} else {
return Optional.empty();
}
}
if (filter.getField().startsWith(PREFIX_FIELD_DATA_NUMBER)) {
if (!(StringUtils.isEmpty(filter.getMin()) && StringUtils.isEmpty(filter.getMax()))) {
return Optional
.of(LongPoint.newRangeQuery(filter.getField(), stringOfNumberToLongElseMin(filter.getMin()),
stringOfNumberToLongElseMax(filter.getMax())));
} else {
return Optional.empty();
}
}
if (filter.getField().startsWith(PREFIX_FIELD_DATA_BOOLEAN)) {
String value = StringUtils.equalsIgnoreCase(filter.getValueList().get(0), Indexs.BOOLEAN_TRUE_STRING_VALUE)
? BOOLEAN_TRUE_STRING_VALUE
: BOOLEAN_FALSE_STRING_VALUE;
return Optional.of(new TermQuery(new Term(filter.getField(), value)));
}
BooleanQuery.Builder builder = new BooleanQuery.Builder();
filter.getValueList().stream().filter(StringUtils::isNotBlank)
.map(o -> new TermQuery(new Term(filter.getField(), o)))
......@@ -343,7 +402,37 @@ public class Indexs {
return Optional.of(builder.build());
}
public static List<String> adjustFacetField(List<String> filters) {
private static Long stringOfDateToLongElseMin(String text) {
try {
Date date = DateTools.parse(text);
return date.getTime();
} catch (Exception e) {
LOGGER.error(new IllegalArgumentException("text:" + text + " can not parse to date.", e));
}
return Long.MIN_VALUE;
}
private static Long stringOfDateToLongElseMax(String text) {
try {
Date date = DateTools.parse(text);
return date.getTime();
} catch (Exception e) {
LOGGER.error(new IllegalArgumentException("text:" + text + " can not parse to date.", e));
}
return Long.MAX_VALUE;
}
private static Long stringOfNumberToLongElseMin(String text) {
Double value = NumberUtils.toDouble(text, Double.MIN_VALUE);
return org.apache.lucene.util.NumericUtils.doubleToSortableLong(value.doubleValue());
}
private static Long stringOfNumberToLongElseMax(String text) {
Double value = NumberUtils.toDouble(text, Double.MAX_VALUE);
return org.apache.lucene.util.NumericUtils.doubleToSortableLong(value.doubleValue());
}
public static List<String> adjustFacetField(List<String> categories, List<String> filters) {
List<String> list = FACET_FIELDS.stream().filter(o -> (!filters.contains(o))).collect(Collectors.toList());
if (list.contains(FIELD_PROCESSNAME)) {
list.removeAll(Arrays.asList(FIELD_APPLICATIONNAME, FIELD_PROCESSNAME,
......@@ -361,6 +450,9 @@ public class Indexs {
list.removeAll(Arrays.asList(FIELD_APPNAME, FIELD_APPLICATIONNAME,
FIELD_PROCESSNAME));
}
if (!ListTools.contains(categories, Indexs.CATEGORY_PROCESSPLATFORM)) {
list.remove(Indexs.FIELD_COMPLETED);
}
return list;
}
......@@ -372,6 +464,20 @@ public class Indexs {
*/
public static Triple<String, String, String> judgeField(String field) {
if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_DATA)) {
return judgeFieldData(field);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM)) {
return judgeFieldProcessPlatform(field);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_CMS)) {
return judgeFieldCms(field);
} else if (FIXED_DATE_FIELDS.contains(field)) {
return Triple.of(field, field, Indexs.FIELD_TYPE_DATE);
} else {
return Triple.of(field, field, Indexs.FIELD_TYPE_STRING);
}
}
private static Triple<String, String, String> judgeFieldData(String field) {
if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_DATA_STRING)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_DATA_STRING),
Indexs.FIELD_TYPE_STRING);
......@@ -396,29 +502,99 @@ public class Indexs {
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_DATA_BOOLEANS)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_DATA_BOOLEANS),
Indexs.FIELD_TYPE_BOOLEANS);
} else if (FIXED_DATE_FIELDS.contains(field)) {
return Triple.of(field, field, Indexs.FIELD_TYPE_DATE);
} else {
return Triple.of(field, field, Indexs.FIELD_TYPE_STRING);
}
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_DATA_STRING),
Indexs.FIELD_TYPE_STRING);
}
@SuppressWarnings("unchecked")
public static <T> T indexableFieldValue(IndexableField indexableField, String fileType) {
if (null == indexableField) {
return null;
private static Triple<String, String, String> judgeFieldProcessPlatform(String field) {
if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING),
Indexs.FIELD_TYPE_STRING);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_DATE)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_DATE),
Indexs.FIELD_TYPE_DATE);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_NUMBER)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_NUMBER),
Indexs.FIELD_TYPE_NUMBER);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_BOOLEAN)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_BOOLEAN),
Indexs.FIELD_TYPE_BOOLEAN);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRINGS)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRINGS),
Indexs.FIELD_TYPE_STRINGS);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_DATES)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_DATES),
Indexs.FIELD_TYPE_DATES);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_NUMBERS)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_NUMBERS),
Indexs.FIELD_TYPE_NUMBERS);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_BOOLEANS)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_BOOLEANS),
Indexs.FIELD_TYPE_BOOLEANS);
}
if (StringUtils.equalsIgnoreCase(Indexs.FIELD_TYPE_DATE, fileType)) {
Number number = indexableField.numericValue();
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING),
Indexs.FIELD_TYPE_STRING);
}
private static Triple<String, String, String> judgeFieldCms(String field) {
if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_CMS_STRING)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_CMS_STRING),
Indexs.FIELD_TYPE_STRING);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_CMS_DATE)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_CMS_DATE),
Indexs.FIELD_TYPE_DATE);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_CMS_NUMBER)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_CMS_NUMBER),
Indexs.FIELD_TYPE_NUMBER);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_CMS_BOOLEAN)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_CMS_BOOLEAN),
Indexs.FIELD_TYPE_BOOLEAN);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_CMS_STRINGS)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_CMS_STRINGS),
Indexs.FIELD_TYPE_STRINGS);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_CMS_DATES)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_CMS_DATES),
Indexs.FIELD_TYPE_DATES);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_CMS_NUMBERS)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_CMS_NUMBERS),
Indexs.FIELD_TYPE_NUMBERS);
} else if (StringUtils.startsWith(field, Indexs.PREFIX_FIELD_CMS_BOOLEANS)) {
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_CMS_BOOLEANS),
Indexs.FIELD_TYPE_BOOLEANS);
}
return Triple.of(field, StringUtils.substringAfter(field, Indexs.PREFIX_FIELD_CMS_STRING),
Indexs.FIELD_TYPE_STRING);
}
@SuppressWarnings("unchecked")
public static <T> T indexableFieldValue(IndexableField[] indexableFields, String fileType) {
if (StringUtils.equalsIgnoreCase(Indexs.FIELD_TYPE_DATES, fileType)) {
return (T) Stream.of(indexableFields).map(IndexableField::numericValue).filter(o -> !Objects.isNull(o))
.<Date>map(o -> new Date(o.longValue())).collect(Collectors.toList());
} else if (StringUtils.equalsIgnoreCase(Indexs.FIELD_TYPE_NUMBERS, fileType)) {
return (T) Stream.of(indexableFields).map(IndexableField::numericValue).filter(o -> !Objects.isNull(o))
.<Double>map(o -> Double.valueOf(NumericUtils.sortableLongToDouble(o.longValue())))
.collect(Collectors.toList());
} else if (StringUtils.equalsIgnoreCase(Indexs.FIELD_TYPE_BOOLEANS, fileType)) {
return (T) Stream.of(indexableFields).map(IndexableField::stringValue).filter(o -> !Objects.isNull(o))
.<Boolean>map(o -> Boolean.valueOf(StringUtils.equalsIgnoreCase(o, BOOLEAN_TRUE_STRING_VALUE)))
.collect(Collectors.toList());
} else if (StringUtils.equalsIgnoreCase(Indexs.FIELD_TYPE_STRINGS, fileType)) {
return (T) Stream.of(indexableFields).<String>map(IndexableField::stringValue)
.filter(o -> !Objects.isNull(o))
.collect(Collectors.toList());
} else if (StringUtils.equalsIgnoreCase(Indexs.FIELD_TYPE_DATE, fileType)) {
Number number = indexableFields[0].numericValue();
return (null != number) ? (T) new Date(number.longValue()) : null;
} else if (StringUtils.equalsIgnoreCase(Indexs.FIELD_TYPE_NUMBER, fileType)) {
Number number = indexableField.numericValue();
Number number = indexableFields[0].numericValue();
return (null != number) ? (T) Double.valueOf(NumericUtils.sortableLongToDouble(number.longValue())) : null;
} else if (StringUtils.equalsIgnoreCase(Indexs.FIELD_TYPE_BOOLEAN, fileType)) {
Number number = indexableField.numericValue();
return (null != number) ? (T) Boolean.valueOf(number.longValue() != 0L) : null;
String str = indexableFields[0].stringValue();
return (T) Boolean.valueOf(StringUtils.equalsIgnoreCase(str, BOOLEAN_TRUE_STRING_VALUE));
} else {
String str = indexableField.stringValue();
String str = indexableFields[0].stringValue();
return (null != str) ? (T) str : null;
}
}
......
package com.x.query.core.express.index;
import java.util.Objects;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
......@@ -20,6 +22,24 @@ public class WoField extends GsonPropertyObject {
this.fieldType = fieldType;
}
@Override
public int hashCode() {
return Objects.hash(field, fieldType, name);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
WoField other = (WoField) obj;
return Objects.equals(field, other.field) && Objects.equals(fieldType, other.fieldType)
&& Objects.equals(name, other.name);
}
@FieldDescribe("字段标识.")
@Schema(description = "字段标识.")
private String field;
......
package com.x.query.service.processing.index;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -7,6 +8,7 @@ import java.util.Map;
import java.util.Objects;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.NumericDocValuesField;
......@@ -51,8 +53,6 @@ public class Doc extends GsonPropertyObject {
private String creatorUnit;
private Boolean completed;
private List<String> readers;
private Map<String, String> stringRepo = new HashMap<>();
......@@ -60,92 +60,10 @@ public class Doc extends GsonPropertyObject {
private Map<String, Boolean> booleanRepo = new HashMap<>();
private Map<String, Number> numberRepo = new HashMap<>();
private Map<String, List<String>> stringListRepo = new HashMap<>();
private Map<String, List<Date>> dateListRepo = new HashMap<>();
private Map<String, List<Boolean>> booleanListRepo = new HashMap<>();
private Map<String, List<Number>> numberListRepo = new HashMap<>();
private Map<String, String> dataStringRepo = new HashMap<>();
private Map<String, Date> dataDateRepo = new HashMap<>();
private Map<String, Boolean> dataBooleanRepo = new HashMap<>();
private Map<String, Number> dataNumberRepo = new HashMap<>();
private Map<String, List<String>> dataStringListRepo = new HashMap<>();
private Map<String, List<Date>> dataDateListRepo = new HashMap<>();
private Map<String, List<Boolean>> dataBooleanListRepo = new HashMap<>();
private Map<String, List<Number>> dataNumberListRepo = new HashMap<>();
public Boolean getCompleted() {
return completed;
}
public void setCompleted(Boolean completed) {
this.completed = completed;
}
public Map<String, String> getStringRepo() {
return stringRepo;
}
public Map<String, Date> getDateRepo() {
return dateRepo;
}
public Map<String, Boolean> getBooleanRepo() {
return booleanRepo;
}
public Map<String, Number> getNumberRepo() {
return numberRepo;
}
public Map<String, List<String>> getStringListRepo() {
return stringListRepo;
}
public Map<String, List<Date>> getDateListRepo() {
return dateListRepo;
}
public Map<String, List<Boolean>> getBooleanListRepo() {
return booleanListRepo;
}
public Map<String, List<Number>> getNumberListRepo() {
return numberListRepo;
}
public Map<String, String> getDataStringRepo() {
return dataStringRepo;
}
public Map<String, Date> getDataDateRepo() {
return dataDateRepo;
}
public Map<String, Boolean> getDataBooleanRepo() {
return dataBooleanRepo;
}
public Map<String, Number> getDataNumberRepo() {
return dataNumberRepo;
}
public Map<String, List<String>> getDataStringListRepo() {
return dataStringListRepo;
}
public Map<String, List<Date>> getDataDateListRepo() {
return dataDateListRepo;
}
public Map<String, List<Boolean>> getDataBooleanListRepo() {
return dataBooleanListRepo;
}
public Map<String, List<Number>> getDataNumberListRepo() {
return dataNumberListRepo;
}
private Map<String, Collection<String>> stringsRepo = new HashMap<>();
private Map<String, Collection<Date>> datesRepo = new HashMap<>();
private Map<String, Collection<Boolean>> booleansRepo = new HashMap<>();
private Map<String, Collection<Number>> numbersRepo = new HashMap<>();
public String getAttachment() {
return attachment;
......@@ -267,74 +185,66 @@ public class Doc extends GsonPropertyObject {
this.updateTimeMonth = updateTimeMonth;
}
public void addString(String name, String value) {
stringRepo.put(name, value);
}
public void addDate(String name, Date value) {
dateRepo.put(name, value);
}
public void addBoolean(String name, Boolean value) {
booleanRepo.put(name, value);
}
public void addNumber(String name, Number value) {
numberRepo.put(name, value);
}
public void addStringList(String name, List<String> values) {
stringListRepo.put(name, values);
}
public void addDateList(String name, List<Date> values) {
dateListRepo.put(name, values);
}
public void addBooleanList(String name, List<Boolean> values) {
booleanListRepo.put(name, values);
}
public void addNumberList(String name, List<Number> values) {
numberListRepo.put(name, values);
}
public void dataAddString(String name, String value) {
dataStringRepo.put(name, value);
public Doc addString(String prefix, String field, String value) {
if (StringUtils.isNotBlank(value)) {
this.stringRepo.put(prefix + field, value);
}
return this;
}
public void dataAddDate(String name, Date value) {
dataDateRepo.put(name, value);
public Doc addDate(String prefix, String field, Date value) {
if (null != value) {
this.dateRepo.put(prefix + field, value);
}
return this;
}
public void dataAddBoolean(String name, Boolean value) {
dataBooleanRepo.put(name, value);
public Doc addBoolean(String prefix, String field, Boolean value) {
if (null != value) {
this.booleanRepo.put(prefix + field, value);
}
return this;
}
public void dataAddNumber(String name, Number value) {
dataNumberRepo.put(name, value);
public Doc addNumber(String prefix, String field, Number value) {
if (null != value) {
this.numberRepo.put(prefix + field, value);
}
return this;
}
public void dataAddStringList(String name, List<String> values) {
dataStringListRepo.put(name, values);
public Doc addStrings(String prefix, String field, Collection<String> values) {
if ((null != values) && (!values.isEmpty())) {
this.stringsRepo.put(prefix + field, values);
}
return this;
}
public void dataAddDateList(String name, List<Date> values) {
dataDateListRepo.put(name, values);
public Doc addDates(String prefix, String field, Collection<Date> values) {
if ((null != values) && (!values.isEmpty())) {
this.datesRepo.put(prefix + field, values);
}
return this;
}
public void dataAddBooleanList(String name, List<Boolean> values) {
dataBooleanListRepo.put(name, values);
public Doc addBooleans(String prefix, String field, Collection<Boolean> values) {
if ((null != values) && (!values.isEmpty())) {
this.booleansRepo.put(prefix + field, values);
}
return this;
}
public void dataAddNumberList(String name, List<Number> values) {
dataNumberListRepo.put(name, values);
public Doc addNumbers(String prefix, String field, Collection<Number> values) {
if ((null != values) && (!values.isEmpty())) {
this.numbersRepo.put(prefix + field, values);
}
return this;
}
public org.apache.lucene.document.Document toDocument(boolean convertData) {
org.apache.lucene.document.Document document = new org.apache.lucene.document.Document();
document.add(new StringField(Indexs.FIELD_ID, this.getId(), Field.Store.YES));
document.add(new TextField(Indexs.FIELD_TITLE, Objects.toString(this.getTitle(), ""), Field.Store.YES));
addTitle(document, this.getTitle());
document.add(new TextField(Indexs.FIELD_SUMMARY, Objects.toString(this.getSummary(), ""), Field.Store.YES));
document.add(new TextField(Indexs.FIELD_BODY, Objects.toString(this.getBody(), ""), Field.Store.YES));
document.add(
......@@ -349,28 +259,33 @@ public class Doc extends GsonPropertyObject {
addDate(document, Indexs.FIELD_INDEXTIME, new Date());
addDate(document, Indexs.FIELD_CREATETIME, this.getCreateTime());
addDate(document, Indexs.FIELD_UPDATETIME, this.getUpdateTime());
addBoolean(document, Indexs.FIELD_COMPLETED, this.getCompleted());
if (convertData) {
this.getStringRepo().entrySet().stream().filter(o -> null != o.getValue())
this.stringRepo.entrySet().stream().filter(o -> null != o.getValue())
.forEach(o -> addString(document, o.getKey(), o.getValue()));
this.getDateRepo().entrySet().stream().filter(o -> null != o.getValue())
this.dateRepo.entrySet().stream().filter(o -> null != o.getValue())
.forEach(o -> addDate(document, o.getKey(), o.getValue()));
this.getNumberRepo().entrySet().stream().filter(o -> null != o.getValue())
this.numberRepo.entrySet().stream().filter(o -> null != o.getValue())
.forEach(o -> addNumber(document, o.getKey(), o.getValue()));
this.getBooleanRepo().entrySet().stream().filter(o -> null != o.getValue())
.forEach(o -> addBoolean(document, o.getKey(), o.getValue()));
this.getDataStringRepo().entrySet().stream().filter(o -> null != o.getValue())
.forEach(o -> addString(document, Indexs.PREFIX_FIELD_DATA_STRING + o.getKey(), o.getValue()));
this.getDataDateRepo().entrySet().stream().filter(o -> null != o.getValue())
.forEach(o -> addDate(document, Indexs.PREFIX_FIELD_DATA_DATE + o.getKey(), o.getValue()));
this.getDataNumberRepo().entrySet().stream().filter(o -> null != o.getValue())
.forEach(o -> addNumber(document, Indexs.PREFIX_FIELD_DATA_NUMBER + o.getKey(), o.getValue()));
this.getDataBooleanRepo().entrySet().stream().filter(o -> null != o.getValue()).forEach(
o -> addBoolean(document, Indexs.PREFIX_FIELD_DATA_BOOLEAN + o.getKey(), o.getValue()));
this.booleanRepo.entrySet().stream().filter(o -> null != o.getValue()).forEach(
o -> addBoolean(document, o.getKey(), o.getValue()));
this.stringsRepo.entrySet().stream().filter(o -> null != o.getValue())
.forEach(o -> addStrings(document, o.getKey(), o.getValue()));
this.datesRepo.entrySet().stream().filter(o -> null != o.getValue())
.forEach(o -> addDates(document, o.getKey(), o.getValue()));
this.numbersRepo.entrySet().stream().filter(o -> null != o.getValue())
.forEach(o -> addNumbers(document, o.getKey(), o.getValue()));
this.booleansRepo.entrySet().stream().filter(o -> null != o.getValue()).forEach(
o -> addBooleans(document, o.getKey(), o.getValue()));
}
return document;
}
private void addTitle(org.apache.lucene.document.Document document, String value) {
String str = Objects.toString(this.getTitle(), "");
document.add(new TextField(Indexs.FIELD_TITLE, str, Field.Store.YES));
document.add(new SortedDocValuesField(Indexs.FIELD_TITLE, new BytesRef(str)));
}
private void addString(org.apache.lucene.document.Document document, String field, String value) {
document.add(new SortedDocValuesField(field, new BytesRef(value)));
document.add(new StringField(field, value, Field.Store.YES));
......@@ -391,10 +306,40 @@ public class Doc extends GsonPropertyObject {
}
private static void addBoolean(org.apache.lucene.document.Document document, String field, Boolean value) {
long store = BooleanUtils.isTrue(value) ? 1L : 0L;
document.add(new NumericDocValuesField(field, store));
document.add(new LongPoint(field, store));
document.add(new StoredField(field, store));
String store = BooleanUtils.isTrue(value) ? Indexs.BOOLEAN_TRUE_STRING_VALUE
: Indexs.BOOLEAN_FALSE_STRING_VALUE;
document.add(new SortedDocValuesField(field, new BytesRef(store)));
document.add(new StringField(field, store, Field.Store.YES));
}
private void addStrings(org.apache.lucene.document.Document document, String field, Collection<String> values) {
values.stream().filter(o -> !Objects.isNull(o))
.forEach(o -> document.add(new StringField(field, o, Field.Store.YES)));
}
private void addNumbers(org.apache.lucene.document.Document document, String field, Collection<Number> values) {
values.stream().filter(o -> !Objects.isNull(o)).forEach(o -> {
long store = org.apache.lucene.util.NumericUtils.doubleToSortableLong(o.doubleValue());
document.add(new LongPoint(field, store));
document.add(new StoredField(field, store));
});
}
private void addDates(org.apache.lucene.document.Document document, String field, Collection<Date> values) {
values.stream().filter(o -> !Objects.isNull(o)).forEach(o -> {
long store = o.getTime();
document.add(new LongPoint(field, store));
document.add(new StoredField(field, store));
});
}
private void addBooleans(org.apache.lucene.document.Document document, String field,
Collection<Boolean> values) {
values.stream().filter(o -> !Objects.isNull(o)).forEach(o -> {
String store = BooleanUtils.isTrue(o) ? Indexs.BOOLEAN_TRUE_STRING_VALUE
: Indexs.BOOLEAN_FALSE_STRING_VALUE;
document.add(new StringField(field, store, Field.Store.YES));
});
}
}
\ No newline at end of file
......@@ -26,7 +26,6 @@ import com.x.base.core.entity.dataitem.ItemCategory;
import com.x.base.core.project.bean.tuple.Pair;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
......@@ -38,6 +37,8 @@ import com.x.cms.core.entity.FileInfo;
import com.x.processplatform.core.entity.content.Attachment;
import com.x.processplatform.core.entity.content.Data;
import com.x.processplatform.core.entity.content.Review;
import com.x.processplatform.core.entity.content.Task;
import com.x.processplatform.core.entity.content.TaskCompleted;
import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.core.entity.element.Process;
......@@ -56,6 +57,7 @@ public class DocFunction {
private static final List<String> PROCESSPLATFORM_REVIEW_FIELDS = new UnmodifiableList<>(
Arrays.asList(Review.person_FIELDNAME));
private static final List<String> CMS_REVIEW_FIELDS = new UnmodifiableList<>(
Arrays.asList(com.x.cms.core.entity.Review.permissionObj_FIELDNAME));
......@@ -68,9 +70,9 @@ public class DocFunction {
Work work = param.first().entityManagerContainer().find(param.second(),
Work.class);
if (null != work) {
LOGGER.debug("DocFunction wrapWork:{}.", param.second());
Doc doc = new Doc();
doc.setReaders(readers(param.first(), work));
doc.setCompleted(false);
doc.setId(work.getJob());
doc.setCategory(Indexs.CATEGORY_PROCESSPLATFORM);
doc.setType(Indexs.TYPE_WORKCOMPLETED);
......@@ -82,15 +84,25 @@ public class DocFunction {
doc.setUpdateTimeMonth(DateTools.format(work.getUpdateTime(), DateTools.format_yyyyMM));
doc.setCreatorPerson(OrganizationDefinition.name(work.getCreatorPerson()));
doc.setCreatorUnit(OrganizationDefinition.name(work.getCreatorUnit()));
doc.addString(Indexs.FIELD_CREATORUNITLEVELNAME, work.getCreatorUnitLevelName());
doc.addString(Indexs.FIELD_APPLICATION, work.getApplication());
doc.addString(Indexs.FIELD_APPLICATIONNAME, work.getApplicationName());
doc.addString(Indexs.FIELD_APPLICATIONALIAS, work.getApplicationAlias());
doc.addString(Indexs.FIELD_PROCESS, work.getProcess());
doc.addString(Indexs.FIELD_PROCESSNAME, work.getProcessName());
doc.addString(Indexs.FIELD_PROCESSALIAS, work.getProcessAlias());
doc.addString(Indexs.FIELD_JOB, work.getJob());
doc.addString(Indexs.FIELD_SERIAL, work.getSerial());
doc.addBoolean(Indexs.PREFIX_FIELD_PROCESSPLATFORM_BOOLEAN, TaskCompleted.completed_FIELDNAME, false);
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, Work.creatorUnitLevelName_FIELDNAME,
work.getCreatorUnitLevelName());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, Work.application_FIELDNAME,
work.getApplication());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, Work.applicationName_FIELDNAME,
work.getApplicationName());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, Work.applicationAlias_FIELDNAME,
work.getApplicationAlias());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, Work.process_FIELDNAME, work.getProcess());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, Work.processName_FIELDNAME,
work.getProcessName());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, Work.processAlias_FIELDNAME,
work.getProcessAlias());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, Work.job_FIELDNAME, work.getJob());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, Work.serial_FIELDNAME, work.getSerial());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, Work.activityName_FIELDNAME,
work.getActivityName());
workAddTaskPersonNames(doc, param.first(), work);
update(param.first(), work, doc);
return Pair.of(work.getApplication(), Optional.of(doc));
}
......@@ -105,9 +117,9 @@ public class DocFunction {
WorkCompleted workCompleted = param.first().entityManagerContainer().find(param.second(),
WorkCompleted.class);
if (null != workCompleted) {
LOGGER.debug("DocFunction wrapWorkCompleted:{}.", param.second());
Doc doc = new Doc();
doc.setReaders(readers(param.first(), workCompleted));
doc.setCompleted(true);
doc.setId(workCompleted.getJob());
doc.setCategory(Indexs.CATEGORY_PROCESSPLATFORM);
doc.setType(Indexs.TYPE_WORKCOMPLETED);
......@@ -119,17 +131,29 @@ public class DocFunction {
doc.setUpdateTimeMonth(DateTools.format(workCompleted.getUpdateTime(), DateTools.format_yyyyMM));
doc.setCreatorPerson(OrganizationDefinition.name(workCompleted.getCreatorPerson()));
doc.setCreatorUnit(OrganizationDefinition.name(workCompleted.getCreatorUnit()));
doc.addString(Indexs.FIELD_CREATORUNITLEVELNAME, workCompleted.getCreatorUnitLevelName());
doc.addString(Indexs.FIELD_APPLICATION, workCompleted.getApplication());
doc.addString(Indexs.FIELD_APPLICATIONNAME, workCompleted.getApplicationName());
doc.addString(Indexs.FIELD_APPLICATIONALIAS, workCompleted.getApplicationAlias());
doc.addString(Indexs.FIELD_PROCESS, workCompleted.getProcess());
doc.addString(Indexs.FIELD_PROCESSNAME, workCompleted.getProcessName());
doc.addString(Indexs.FIELD_PROCESSALIAS, workCompleted.getProcessAlias());
doc.addString(Indexs.FIELD_JOB, workCompleted.getJob());
doc.addString(Indexs.FIELD_SERIAL, workCompleted.getSerial());
doc.addBoolean(Indexs.FIELD_EXPIRED, workCompleted.getExpired());
doc.addDate(Indexs.FIELD_EXPIRETIME, workCompleted.getExpireTime());
doc.addBoolean(Indexs.PREFIX_FIELD_PROCESSPLATFORM_BOOLEAN, TaskCompleted.completed_FIELDNAME, true);
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, WorkCompleted.creatorUnitLevelName_FIELDNAME,
workCompleted.getCreatorUnitLevelName());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, WorkCompleted.application_FIELDNAME,
workCompleted.getApplication());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, WorkCompleted.applicationName_FIELDNAME,
workCompleted.getApplicationName());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, WorkCompleted.applicationAlias_FIELDNAME,
workCompleted.getApplicationAlias());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, WorkCompleted.process_FIELDNAME,
workCompleted.getProcess());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, WorkCompleted.processName_FIELDNAME,
workCompleted.getProcessName());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, WorkCompleted.processAlias_FIELDNAME,
workCompleted.getProcessAlias());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, WorkCompleted.job_FIELDNAME,
workCompleted.getJob());
doc.addString(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRING, WorkCompleted.serial_FIELDNAME,
workCompleted.getSerial());
doc.addBoolean(Indexs.PREFIX_FIELD_PROCESSPLATFORM_BOOLEAN, WorkCompleted.expired_FIELDNAME,
workCompleted.getExpired());
doc.addDate(Indexs.PREFIX_FIELD_PROCESSPLATFORM_DATE, WorkCompleted.expireTime_FIELDNAME,
workCompleted.getExpireTime());
update(param.first(), workCompleted, doc);
return Pair.of(workCompleted.getApplication(), Optional.of(doc));
}
......@@ -143,9 +167,9 @@ public class DocFunction {
try {
Document document = param.first().entityManagerContainer().find(param.second(), Document.class);
if (null != document) {
LOGGER.debug("DocFunction wrapDocument:{}.", param.second());
Doc doc = new Doc();
doc.setReaders(readers(param.first(), document));
doc.setCompleted(true);
doc.setId(document.getId());
doc.setCategory(Indexs.CATEGORY_CMS);
doc.setType(Indexs.TYPE_DOCUMENT);
......@@ -157,15 +181,19 @@ public class DocFunction {
doc.setUpdateTimeMonth(DateTools.format(document.getUpdateTime(), DateTools.format_yyyyMM));
doc.setCreatorPerson(OrganizationDefinition.name(document.getCreatorPerson()));
doc.setCreatorUnit(OrganizationDefinition.name(document.getCreatorUnitName()));
doc.addString(Indexs.FIELD_APPID, document.getAppId());
doc.addString(Indexs.FIELD_APPNAME, document.getAppName());
doc.addString(Indexs.FIELD_APPALIAS, document.getAppAlias());
doc.addString(Indexs.FIELD_CATEGORYID, document.getCategoryId());
doc.addString(Indexs.FIELD_CATEGORYNAME, document.getCategoryName());
doc.addString(Indexs.FIELD_CATEGORYALIAS, document.getCategoryAlias());
doc.addString(Indexs.FIELD_DESCRIPTION, document.getDescription());
doc.addDate(Indexs.FIELD_PUBLISHTIME, document.getPublishTime());
doc.addDate(Indexs.FIELD_MODIFYTIME, document.getModifyTime());
doc.addString(Indexs.PREFIX_FIELD_CMS_STRING, Document.appId_FIELDNAME,
document.getAppId());
doc.addString(Indexs.PREFIX_FIELD_CMS_STRING, Document.appName_FIELDNAME,
document.getAppName());
doc.addString(Indexs.PREFIX_FIELD_CMS_STRING, Document.appAlias_FIELDNAME, document.getAppAlias());
doc.addString(Indexs.PREFIX_FIELD_CMS_STRING, Document.categoryId_FIELDNAME, document.getCategoryId());
doc.addString(Indexs.PREFIX_FIELD_CMS_STRING, Document.categoryName_FIELDNAME,
document.getCategoryName());
doc.addString(Indexs.PREFIX_FIELD_CMS_STRING, Document.categoryAlias_FIELDNAME,
document.getCategoryAlias());
doc.addString(Indexs.PREFIX_FIELD_CMS_STRING, Indexs.FIELD_DESCRIPTION, document.getDescription());
doc.addDate(Indexs.PREFIX_FIELD_CMS_STRING, Indexs.FIELD_PUBLISHTIME, document.getPublishTime());
doc.addDate(Indexs.PREFIX_FIELD_CMS_STRING, Indexs.FIELD_MODIFYTIME, document.getModifyTime());
update(param.first(), document, doc, Config.query().index().getDataStringThreshold());
return Pair.of(document.getAppId(), Optional.of(doc));
}
......@@ -194,6 +222,19 @@ public class DocFunction {
return list.stream().distinct().collect(Collectors.toList());
}
private static void workAddTaskPersonNames(Doc doc, Business business, Work work) throws Exception {
List<Task> list = business.entityManagerContainer().listEqualAndEqual(Task.class, Task.job_FIELDNAME,
work.getJob(), Task.application_FIELDNAME, work.getApplication());
doc.addStrings(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRINGS, Indexs.FIELD_ROCESSPLATFORM_TASKPERSONNAMES,
list.stream().map(Task::getPerson).filter(StringUtils::isNotBlank)
.map(OrganizationDefinition::name).distinct()
.collect(Collectors.toList()));
doc.addStrings(Indexs.PREFIX_FIELD_PROCESSPLATFORM_STRINGS, Indexs.FIELD_ROCESSPLATFORM_PRETASKPERSONNAMES,
list.stream().map(Task::getPerson).filter(StringUtils::isNotBlank)
.map(OrganizationDefinition::name).distinct()
.collect(Collectors.toList()));
}
private static List<String> readers(Business business, WorkCompleted workCompleted) throws Exception {
List<String> list = business.entityManagerContainer()
.fetchEqualAndEqual(Review.class, PROCESSPLATFORM_REVIEW_FIELDS, Review.job_FIELDNAME,
......@@ -226,8 +267,9 @@ public class DocFunction {
}
private static void update(Business business, Work work, Doc wrap) {
List<Item> items = null;
try {
List<Item> items = business.entityManagerContainer().listEqualAndEqual(Item.class,
items = business.entityManagerContainer().listEqualAndEqual(Item.class,
DataItem.bundle_FIELDNAME,
work.getJob(), DataItem.itemCategory_FIELDNAME, ItemCategory.pp);
if (!ListTools.isEmpty(items)) {
......@@ -243,13 +285,13 @@ public class DocFunction {
LOGGER.warn("class:DocFunction, function:update work:{}, items is empty.", work.getId());
}
} catch (Exception e) {
LOGGER.error(e);
LOGGER.error(new ExceptionWorkUpdate(e, work.getId(), items));
}
}
private static void update(Business business, WorkCompleted workCompleted, Doc wrap) {
List<Item> items = null;
try {
List<Item> items = null;
if (BooleanUtils.isTrue(workCompleted.getMerged())) {
Data data = workCompleted.getProperties().getData();
items = CONVERTER.disassemble(gson.toJsonTree(data));
......@@ -271,14 +313,15 @@ public class DocFunction {
workCompleted.getId());
}
} catch (Exception e) {
LOGGER.error(e);
LOGGER.error(new ExceptionWorkCompletedUpdate(e, workCompleted.getId(), items));
}
}
private static void update(Business business, com.x.cms.core.entity.Document document, Doc wrap,
Integer dataStringThreshold) {
List<Item> items = null;
try {
List<Item> items = business.entityManagerContainer().listEqualAndEqual(Item.class,
items = business.entityManagerContainer().listEqualAndEqual(Item.class,
DataItem.bundle_FIELDNAME, document.getId(), DataItem.itemCategory_FIELDNAME, ItemCategory.cms);
if (!ListTools.isEmpty(items)) {
wrap.setBody(DataItemConverter.ItemText.text(items, true, true, true, true, true, ","));
......@@ -293,7 +336,7 @@ public class DocFunction {
LOGGER.warn("class:DocFunction, function:update document:{}, items is empty.", document.getId());
}
} catch (Exception e) {
LOGGER.error(e);
LOGGER.error(new ExceptionDocumentUpdate(e, document.getId(), items));
}
}
......@@ -317,18 +360,18 @@ public class DocFunction {
if (StringUtils.length(value) <= dataStringThreshold) {
if (BooleanUtils.isTrue(DateTools.isDateTimeOrDateOrTime(value))) {
try {
doc.addDate(Indexs.PREFIX_FIELD_DATA_DATE + name, DateTools.parse(value));
doc.addDate(Indexs.PREFIX_FIELD_DATA_DATE, name, DateTools.parse(value));
} catch (Exception e) {
LOGGER.error(e);
}
} else {
doc.addString(Indexs.PREFIX_FIELD_DATA_STRING + name, value);
doc.addString(Indexs.PREFIX_FIELD_DATA_STRING, name, value);
}
}
} else if (jsonPrimitive.isBoolean()) {
doc.addBoolean(Indexs.PREFIX_FIELD_DATA_BOOLEAN + name, jsonPrimitive.getAsBoolean());
doc.addBoolean(Indexs.PREFIX_FIELD_DATA_BOOLEAN, name, jsonPrimitive.getAsBoolean());
} else if (jsonPrimitive.isNumber()) {
doc.addNumber(Indexs.PREFIX_FIELD_DATA_NUMBER + name, jsonPrimitive.getAsNumber());
doc.addNumber(Indexs.PREFIX_FIELD_DATA_NUMBER, name, jsonPrimitive.getAsNumber());
}
}
......@@ -344,10 +387,10 @@ public class DocFunction {
if (BooleanUtils.isTrue(list.stream().map(JsonPrimitive::isString).reduce(true, (a, b) -> a && b))) {
updateArrayString(doc, name, list);
} else if (BooleanUtils.isTrue(list.stream().map(JsonPrimitive::isNumber).reduce(true, (a, b) -> a && b))) {
doc.addNumberList(Indexs.PREFIX_FIELD_DATA_NUMBERS + name,
doc.addNumbers(Indexs.PREFIX_FIELD_DATA_NUMBERS, name,
list.stream().map(JsonPrimitive::getAsNumber).collect(Collectors.toList()));
} else if (BooleanUtils.isTrue(list.stream().map(JsonPrimitive::isBoolean).reduce(true, (a, b) -> a && b))) {
doc.addBooleanList(Indexs.PREFIX_FIELD_DATA_BOOLEANS + name,
doc.addBooleans(Indexs.PREFIX_FIELD_DATA_BOOLEANS, name,
list.stream().map(JsonPrimitive::getAsBoolean).collect(Collectors.toList()));
}
}
......@@ -356,7 +399,7 @@ public class DocFunction {
List<String> values = list.stream().map(JsonPrimitive::getAsString).collect(Collectors.toList());
if (BooleanUtils
.isTrue(values.stream().map(DateTools::isDateTimeOrDateOrTime).reduce(true, (a, b) -> a && b))) {
wrap.addDateList(Indexs.PREFIX_FIELD_DATA_DATES + name, values.stream().map(s -> {
wrap.addDates(Indexs.PREFIX_FIELD_DATA_DATES, name, values.stream().map(s -> {
try {
return DateTools.parse(s);
} catch (Exception e) {
......@@ -365,7 +408,7 @@ public class DocFunction {
return null;
}).collect(Collectors.toList()));
} else {
wrap.addStringList(Indexs.PREFIX_FIELD_DATA_STRINGS + name, values);
wrap.addStrings(Indexs.PREFIX_FIELD_DATA_STRINGS, name, values);
}
}
......
package com.x.query.service.processing.index;
import java.util.List;
import com.x.base.core.project.exception.LanguagePromptException;
import com.x.query.core.entity.Item;
class ExceptionDocumentUpdate extends LanguagePromptException {
private static final long serialVersionUID = -9089355008820123519L;
ExceptionDocumentUpdate(Throwable th, String document, List<Item> items) {
super(th, "update document:{} error, items:{}.", document, items);
}
}
package com.x.query.service.processing.index;
import java.util.List;
import com.x.base.core.project.exception.LanguagePromptException;
import com.x.query.core.entity.Item;
class ExceptionWorkCompletedUpdate extends LanguagePromptException {
private static final long serialVersionUID = -9089355008820123519L;
ExceptionWorkCompletedUpdate(Throwable th, String workCompketed, List<Item> items) {
super(th, "update workCompketed:{} error, items:{}.", workCompketed, items);
}
}
package com.x.query.service.processing.index;
import java.util.List;
import com.x.base.core.project.exception.LanguagePromptException;
import com.x.query.core.entity.Item;
class ExceptionWorkUpdate extends LanguagePromptException {
private static final long serialVersionUID = -9089355008820123519L;
ExceptionWorkUpdate(Throwable th, String work, List<Item> items) {
super(th, "update work:{} error, items:{}.", work, items);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册