diff --git a/src/main/java/com/dev/energy/server/action/QueryAction.java b/src/main/java/com/dev/energy/server/action/QueryAction.java new file mode 100644 index 0000000..dfc6d39 --- /dev/null +++ b/src/main/java/com/dev/energy/server/action/QueryAction.java @@ -0,0 +1,1033 @@ +package com.dev.energy.server.action; + + + +import com.dev.energy.client.config.page.ColumnProperty; +import com.dev.energy.client.config.page.TableConfig; +import com.dev.energy.client.exception.BaseException; +import com.dev.energy.client.exception.RemoteQueryException; +import com.dev.energy.client.model.CustomerSearchDetail; +import com.dev.energy.client.model.HqlParam; +import com.dev.energy.client.ui.support.InitListenerContext; +import com.dev.energy.client.ui.table.RowData; +import com.dev.energy.client.ui.transobj.InitTransObject; +import com.dev.energy.server.config.UniConfig; +import com.dev.energy.server.config.ui.engine.ComplexComponent; +import com.dev.energy.server.config.ui.engine.DataSource; +import com.dev.energy.server.config.ui.engine.Page; +import com.dev.energy.server.config.ui.engine.UI; +import com.dev.energy.server.exception.EnergyServerRuntimeException; +import com.dev.energy.server.format.Formatter; +import com.dev.energy.server.model.Entity; +import com.dev.energy.server.model.security.User; +import com.dev.energy.server.model.table.TableColumn; +import com.dev.energy.server.model.table.TableInfo; +import com.dev.energy.server.service.GridQueryManager; +import com.dev.energy.server.service.ValueListQueryManager; +import com.dev.energy.server.service.intercepter.ActionTurnController; +import com.dev.energy.server.service.intercepter.AfterReturnIntercepter; +import com.dev.energy.server.service.table.QueryTable; +import com.dev.energy.server.service.table.TableInfoManager; +import com.dev.energy.server.servlet.LoginServlet; +import com.dev.energy.server.util.DataSourceParamUtil; +import com.dev.energy.server.util.HqlUtils; +import com.dev.energy.server.util.LocalizedMessage; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.sql.Date; +import java.sql.Timestamp; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import net.mlw.vlh.ValueList; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.util.Assert; + +/* loaded from: high-server-1.1.3.jar:com/dev/energy/server/action/QueryAction.class */ +public class QueryAction extends AbstractAction implements ApplicationContextAware { + protected ApplicationContext ac; + private GridQueryManager gridQueryManager; + private TableInfoManager tableInfoManager; + private DataSourceParamUtil dataSourceParamUtil; + private ValueListQueryManager valueListQueryManager; + private UniConfig uniConfig; + private final DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); + private final DateFormat datetimeFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + private static Logger log= Logger.getLogger(QueryAction.class); + + protected RowData[] buildRowData(List queryResult) { + return buildRowData(null, queryResult); + } + + protected RowData[] buildRowData(TableConfig tableConfig, List queryResult) { + List result = new ArrayList<>(); + for (Object value : queryResult) { + Object[] objs = value instanceof Object[] ? (Object[]) value : new Object[]{value}; + RowData rowData = new RowData(); + for (Object obj : objs) { + rowData.addColumnValue(convertToStringIfNecessary(obj)); + } + if (tableConfig != null) { + for (int j = 0; j < tableConfig.getColumnProperties().size(); j++) { + ColumnProperty property = (ColumnProperty) tableConfig.getColumnProperties().get(j); + if (property.isVisible()) { + if (property.getFormat() != null && property.getFormat().length() > 0) { + if (!"booleanFormat".equals(property.getFormat()) && !"enumFormat".equals(property.getFormat())) { + Formatter formatter = (Formatter) this.ac.getBean(property.getFormat()); + String columnValue = formatter.format(property.getFormatParam(), objs[property.getValueIndex()], rowData.getColumnValues(), this.referenceModel, this.localeName); + if (StringUtils.isEmpty(columnValue)) { + columnValue = "-"; + } + rowData.getDisplayColumnValues().set(property.getValueIndex(), columnValue); + } + } else { + String columnValue2 = objs[property.getValueIndex()] == null ? "-" : objs[property.getValueIndex()].toString(); + if (StringUtils.isEmpty(columnValue2)) { + columnValue2 = "-"; + } + rowData.getDisplayColumnValues().set(property.getValueIndex(), columnValue2); + } + } + } + } + result.add(rowData); + } + return (RowData[]) result.toArray(new RowData[0]); + } + + private Object convertToStringIfNecessary(Object object) { + if (object == null) { + return "-"; + } + if (object instanceof Long) { + return object; + } + if (object instanceof Date) { + String result = this.dateFormatter.format(object); + if (result.startsWith("1900")) { + result = ""; + } + return result; + } else if (object instanceof Timestamp) { + String result2 = this.datetimeFormatter.format(object); + if (result2.startsWith("1900")) { + result2 = ""; + } + return result2; + } else { + String value = object.toString(); + return StringUtils.isEmpty(value) ? "-" : value; + } + } + + private String convertGlobalParamToHql(String hql, Map params) { + //log.info("开始查询: " + hql); + String value; + String substringBetween = StringUtils.substringBetween(hql, "/~", "~/"); + while (true) { + String _hql = substringBetween; + if (StringUtils.isEmpty(_hql) || StringUtils.isEmpty(StringUtils.substringBetween(_hql, "#{", "}"))) { + break; + } + String sessionParam = StringUtils.substringBetween(_hql, "#{", "}"); + if (!StringUtils.isEmpty(sessionParam)) { + Object sessionValue = this.request.getSession().getAttribute(sessionParam); + if (sessionValue == null) { + sessionValue = this.uniConfig.getGlobalParam(sessionParam, this.referenceModel).getClientGlobal(); + } + if (sessionValue != null) { + if (!(sessionValue instanceof Entity) && !(sessionValue instanceof Collection)) { + if (sessionValue instanceof String) { + value = "'" + sessionValue.toString() + "'"; + } else { + value = sessionValue.toString(); + } + hql = StringUtils.replace(hql, "#{" + sessionParam + "}", value); + } else { + hql = StringUtils.replace(hql, "#{" + sessionParam + "}", "{" + sessionParam + "}"); + params.put(sessionParam, sessionValue); + } + StringUtils.replace(hql, "/~" + _hql + "~/", StringUtils.substring(_hql, _hql.indexOf(":") + 1)); + } else { + throw new EnergyServerRuntimeException("Session parameter [" + sessionParam + "] does contain corresponding value in session attribute"); + } + } + substringBetween = StringUtils.substringBetween(hql, "/~", "~/"); + } + String substringBetween2 = StringUtils.substringBetween(hql, "#{", "}"); + while (true) { + String sessionParam2 = substringBetween2; + if (!StringUtils.isEmpty(sessionParam2)) { + Object sessionValue2 = this.request.getSession().getAttribute(sessionParam2); + if (sessionValue2 == null) { + sessionValue2 = this.uniConfig.getGlobalParam(sessionParam2, this.referenceModel).getClientGlobal(); + } + if (sessionValue2 != null) { + if (!(sessionValue2 instanceof Entity)) { + if (sessionValue2 instanceof String) { + String value2 = "'" + sessionValue2.toString() + "'"; + hql = StringUtils.replace(hql, "#{" + sessionParam2 + "}", value2); + } else if (sessionValue2 instanceof Collection) { + hql = StringUtils.replace(hql, "#{" + sessionParam2 + "}", "{" + sessionParam2 + "}"); + params.put(sessionParam2, sessionValue2); + } else { + String value3 = sessionValue2.toString(); + hql = StringUtils.replace(hql, "#{" + sessionParam2 + "}", value3); + } + } else { + hql = StringUtils.replace(hql, "#{" + sessionParam2 + "}", "{" + sessionParam2 + "}"); + params.put(sessionParam2, sessionValue2); + } + substringBetween2 = StringUtils.substringBetween(hql, "#{", "}"); + } else { + throw new EnergyServerRuntimeException("Session parameter [" + sessionParam2 + "] does contain corresponding value in session attribute"); + } + } else { + if (this.logger.isDebugEnabled()) { + this.logger.debug("Convert session parameters into HQL:" + hql); + } + return hql; + } + } + } + + private String removeHqlWithNullParam2(String hql, Map params) { + String replace; + String substringBetween = StringUtils.substringBetween(hql, "/~", "~/"); + while (true) { + String _hql = substringBetween; + if (StringUtils.isNotEmpty(_hql)) { + String param = StringUtils.substring(_hql, 0, _hql.indexOf(":")).trim(); + Object o = params.get(param); + if (o == null || "".equals(o)) { + params.remove(param); + hql = StringUtils.remove(hql, "/~" + _hql + "~/"); + } else if ((o instanceof Collection) && (((Collection) o).isEmpty() || ((Collection) o).size() == 0)) { + params.remove(param); + hql = StringUtils.remove(hql, "/~" + _hql + "~/"); + } + if (!(o instanceof Entity)) { + String bName = StringUtils.substringBetween(_hql, "{", "}"); + String temp = _hql; + if (StringUtils.isNotEmpty(bName)) { + temp = StringUtils.replace(temp, "{" + bName + "}", ":" + bName); + } + replace = StringUtils.replace(hql, "/~" + _hql + "~/", StringUtils.substring(temp, temp.indexOf(":") + 1)); + } else { + replace = StringUtils.replace(hql, "/~" + _hql + "~/", StringUtils.substring(_hql, _hql.indexOf(":") + 1)); + } + hql = replace; + substringBetween = StringUtils.substringBetween(hql, "/~", "~/"); + } else { + return hql; + } + } + } + + private String removeHqlWithNullParam(String hql, Map params) { + String substringBetween = StringUtils.substringBetween(hql, "/~", "~/"); + while (true) { + String _hql = substringBetween; + if (StringUtils.isNotEmpty(_hql)) { + String param = StringUtils.substring(_hql, 0, _hql.indexOf(":")).trim(); + Object o = params.get(param); + if (o == null || "".equals(o)) { + params.remove(param); + hql = StringUtils.remove(hql, "/~" + _hql + "~/"); + } else if ((o instanceof Collection) && (((Collection) o).isEmpty() || ((Collection) o).size() == 0)) { + params.remove(param); + hql = StringUtils.remove(hql, "/~" + _hql + "~/"); + } + hql = StringUtils.replace(hql, "/~" + _hql + "~/", StringUtils.substring(_hql, _hql.indexOf(":") + 1)); + substringBetween = StringUtils.substringBetween(hql, "/~", "~/"); + } else { + return hql; + } + } + } + + public TableConfig buildGrid(TableConfig tableConfig) { + //log.info("------------------------------------------------------------------------------------------------开始查询------------------------------------------------------------------------------------------------: "); + Object controlResult = actionControlTurnExcute(tableConfig.getPageId(), new Object[]{tableConfig}); + if (controlResult != null) { + return (TableConfig) controlResult; + } + Map params = tableConfig.getParams(); + + for (Object key : params.keySet()) { + Object param=params.get(key); + + String param_str=param.toString(); + //log.info(key.toString()+"====="+param_str+"--"+param_str.indexOf("%")); + if(param_str.indexOf("%")==0){ + //log.info("替换开始"); + params.put(key, param_str.substring(1)); + + log.info("替换------"+key.toString()+"====="+param_str+"--"+param_str.indexOf("%")); + } + + } + + + + params.put("pagingPage", new StringBuilder().append(tableConfig.getCurrentPage()).toString()); + if (!params.containsKey("pagingNumberPer")) { + params.put("pagingNumberPer", new StringBuilder().append(tableConfig.getPagingNumberPer()).toString()); + } + String hql = tableConfig.getHql(); + //log.info("------------------------------------------------------------------------------------------------开始查询HQL------------------------------------------------------------------------------------------------"); + Assert.notNull(hql, String.valueOf(tableConfig.getPageId()) + "'s hql is null!"); + String hql2 = removeHqlWithNullParam(convertGlobalParamToHql(appendHql(hql, params), params), params); + TableConfig result = null; + if (this.logger.isDebugEnabled()) { + this.logger.debug("buildGrid with hql[" + hql2 + "] and params[" + params + "]"); + } + + String hql3 = formateHql(hql2); + if (tableConfig.getDataSourceType().equals(DataSource.HQL_TYPE)) { + int index = containOrderBy(hql3); + if (index == -1) { + hql3 = String.valueOf(hql3) + tableConfig.getSortHql(); + } else if (tableConfig.getSortHql() != null && !"".equals(tableConfig.getSortHql())) { + hql3 = String.valueOf(hql3.substring(0, index)) + tableConfig.getSortHql() + " ," + hql3.substring(index + 8, hql3.length()); + } + //log.info("------------------------------------------------------------------------------------------------查询方式1------------------------------------------------------------------------------------------------ "); + result = buildHqlGrid(tableConfig, hql3, params); + } else if (tableConfig.getDataSourceType().equals(DataSource.JAVA_TYPE)) { + //log.info("------------------------------------------------------------------------------------------------查询方式2------------------------------------------------------------------------------------------------ "); + result = buildJavaGrid(tableConfig, hql3, params); + } + params.clear(); +// log.info("------------------------------------------------------------------------------------------------查询结束------------------------------------------------------------------------------------------------ "); + return result; + } + + public String appendHql(String hql, Map params) { + String str; + if (!params.containsKey("condition")) { + return hql; + } + List details = (List) params.get("condition"); + StringBuffer buf = new StringBuffer(); + for (CustomerSearchDetail detail : details) { + String sign = detail.getQuerySign(); + String property = detail.getProperty(); + String strExtend1 = detail.getStrExtend1(); + String strExtend2 = detail.getStrExtend2(); + String conditionOperator = HqlUtils.getConditionOperator(detail.getOperator()); + buf.append(" " + sign + " " + strExtend1 + property + StringUtils.replace(conditionOperator, "{0}", "{" + property + "}") + strExtend2); + params.put(property, HqlUtils.getCondition(detail)); + } + if (buf.length() <= 0) { + return hql; + } + int oderById = hql.toUpperCase().lastIndexOf("ORDER BY"); + int groupById = hql.toUpperCase().lastIndexOf("GROUP BY"); + if (groupById > 0 && oderById > 0) { + String groupBy = String.valueOf("") + hql.substring(groupById, hql.length()); + str = String.valueOf(hql.substring(0, groupById)) + " " + buf.toString() + " " + groupBy; + } else if (groupById > 0) { + String groupBy2 = String.valueOf("") + hql.substring(groupById, hql.length()); + str = String.valueOf(hql.substring(0, groupById)) + " " + buf.toString() + " " + groupBy2; + } else if (oderById > 0) { + String oderBy = String.valueOf("") + hql.substring(oderById, hql.length()); + str = String.valueOf(hql.substring(0, oderById)) + " " + buf.toString() + " " + oderBy; + } else { + str = String.valueOf(hql) + buf.toString(); + } + return str; + } + + private int containOrderBy(String hql) { + String temp = hql.toUpperCase(); + int index = temp.indexOf("ORDER BY"); + if (index != -1) { + return index; + } + return index; + } + + protected Object actionControlTurnExcute(String pageId, Object[] objs) { + if (this.uniConfig.getPage(this.referenceModel, pageId) == null) { + return null; + } + String controller = this.uniConfig.getPage(this.referenceModel, pageId).getActionController(); + if (!StringUtils.isEmpty(controller)) { + ActionTurnController control = (ActionTurnController) this.ac.getBean(controller); + if (control.isTurn(objs).booleanValue()) { + return control.turnExcute(objs, this.request, this.response, this.referenceModel, this.localeName); + } + return null; + } + return null; + } + + protected TableConfig buildJavaGrid(TableConfig tableConfig, String hql, Map params) { + QueryTable qt = (QueryTable) this.ac.getBean(hql); + qt.setCurrentPage(Integer.parseInt((String) params.get("pagingPage"))); + qt.setPagingNumberPer(Integer.parseInt((String) params.get("pagingNumberPer"))); + List propertiesClone = tableConfig.getSortedPropertiesClone(); + qt.setSortProperties(propertiesClone); + qt.query(params); + tableConfig.setTotalEntry(qt.getTotalNumber()); + tableConfig.setTotalPage(qt.getTotalPages()); + List list = new ArrayList(); + RowData[] rowDatas = buildRowData(tableConfig, qt.getData()); + for (RowData rowData : rowDatas) { + list.add(rowData); + } + tableConfig.setTableRows(list); + return tableConfig; + } + + protected TableConfig buildHqlGrid(TableConfig tableConfig, String hql, Map params) { + try { + ValueList valueList = this.valueListQueryManager.queryByValueList(hql, params); + Assert.notNull(valueList, "valueList is null by hql [" + hql + "]"); + if (valueList == null) { + throw new EnergyServerRuntimeException("Cann't query datas from DataBase! "); + } + initGridInfo(tableConfig, valueList); + return tableConfig; + } catch (Exception e) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e); + } + String mess = LocalizedMessage.getLocalizedMessage("build.exception.message", this.referenceModel, this.localeName); + throw new BaseException(mess); + } + } + + protected TableConfig buildScrollHqlGrid(TableConfig tableConfig, String hql, Map pageParams, Map queryParams) { + try { + ValueList valueList = this.valueListQueryManager.scrollableQuery(hql, pageParams, queryParams); + if (valueList == null) { + throw new EnergyServerRuntimeException("Cann't query datas from DataBase! "); + } + initGridInfo(tableConfig, valueList); + return tableConfig; + } catch (Exception e) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e); + } + String mess = LocalizedMessage.getLocalizedMessage("scrollableQuery.exception.message", this.referenceModel, this.localeName); + throw new BaseException(mess); + } + } + + protected void initGridInfo(TableConfig tableConfig, ValueList valueList) { + tableConfig.setTotalEntry(valueList.getValueListInfo().getTotalNumberOfEntries()); + tableConfig.setTotalPage(valueList.getValueListInfo().getTotalNumberOfPages()); + List list = new ArrayList(); + RowData[] rowDatas = buildRowData(tableConfig, valueList.getList()); + for (RowData rowData : rowDatas) { + list.add(rowData); + } + tableConfig.setTableRows(list); + } + + public Map load(Map params) { + try { + return this.gridQueryManager.load(params); + } catch (Exception e) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e); + } + String mess = LocalizedMessage.getLocalizedMessage("load.exception.message", this.referenceModel, this.localeName); + throw new BaseException(mess); + } + } + + public GridQueryManager getGridQueryManager() { + return this.gridQueryManager; + } + + public void setGridQueryManager(GridQueryManager gridQueryManager) { + this.gridQueryManager = gridQueryManager; + } + + public void saveTableConfig(TableConfig tableConfig) { + TableInfo tableInfo; + User user = (User) getThreadLocalRequest().getSession().getAttribute(LoginServlet.SESSION_USER); + TableInfo tableInfo2 = this.tableInfoManager.getTableInfoByKey(tableConfig.getPageId(), user); + if (tableInfo2 != null) { + tableInfo = this.tableInfoManager.loadTableColumns(tableInfo2); + for (TableColumn column : tableInfo.getColumns()) { + Iterator it = tableConfig.getColumnProperties().iterator(); + while (true) { + if (!it.hasNext()) { + break; + } + Object obj = it.next(); + ColumnProperty property = (ColumnProperty) obj; + if (column.getKey().equals(property.getProperty())) { + column.setVisible(property.isVisible()); + column.setExportExcel(property.isExportExcel()); + column.setSortIndex(property.getSortIndex()); + column.setSortDirection(property.getSortDirection()); + column.setIndex(property.getIndex()); + column.setCurrentSum(property.isCurrentSum()); + column.setCurrentAvg(property.isCurrentAvg()); + column.setTotalAvg(property.isTotalAvg()); + column.setTotalSum(property.isTotalSum()); + break; + } + } + } + } else { + tableInfo = new TableInfo(user, tableConfig.getPageId()); + Set columns = new HashSet<>(); + for (Object obj2 : tableConfig.getColumnProperties()) { + ColumnProperty property2 = (ColumnProperty) obj2; + TableColumn column2 = new TableColumn(); + column2.setTableInfo(tableInfo); + column2.setKey(property2.getProperty()); + column2.setVisible(property2.isVisible()); + column2.setExportExcel(property2.isExportExcel()); + column2.setSortIndex(property2.getSortIndex()); + column2.setSortDirection(property2.getSortDirection()); + column2.setIndex(property2.getIndex()); + column2.setCurrentSum(property2.isCurrentSum()); + column2.setCurrentAvg(property2.isCurrentAvg()); + column2.setTotalAvg(property2.isTotalAvg()); + column2.setTotalSum(property2.isTotalSum()); + columns.add(column2); + } + tableInfo.setColumns(columns); + } + this.tableInfoManager.store(tableInfo); + } + + public TableInfoManager getTableInfoManager() { + return this.tableInfoManager; + } + + public void setTableInfoManager(TableInfoManager tableInfoManager) { + this.tableInfoManager = tableInfoManager; + } + + public void setApplicationContext(ApplicationContext ac) throws BeansException { + this.ac = ac; + } + + private String removeGroupBy(String hql) { + int gbIndex = hql.toLowerCase().indexOf("group by"); + if (gbIndex != -1) { + hql = StringUtils.substring(hql, 0, gbIndex); + } + return hql; + } + + public TableConfig calCurrent(TableConfig tableConfig) { + Map params = tableConfig.getParams(); + params.put("pagingPage", "1"); + String hql = tableConfig.getHql(); + String selectHql = tableConfig.getTotalSelectHql(hql); + if (selectHql.equals("")) { + tableConfig.setCalTotalData(new RowData()); + return tableConfig; + } + if (!StringUtils.isEmpty(tableConfig.getSortHql())) { + hql = String.valueOf(selectHql) + (selectHql.toLowerCase().indexOf("order by") == -1 ? tableConfig.getSortHql() : tableConfig.getSortHql().replace("ORDER BY", ",")); + } + TableConfig config = buildTableHqlGrid(tableConfig, removeHqlWithNullParam(convertGlobalParamToHql(removeGroupBy(hql), params), params), params); + params.clear(); + return config; + } + + protected TableConfig buildTableHqlGrid(TableConfig tableConfig, String hql, Map params) { + try { + ValueList valueList = this.valueListQueryManager.queryByValueList(hql, params); + RowData[] rowData = buildRowData(valueList.getList()); + tableConfig.setCalTotalData(rowData[0]); + return tableConfig; + } catch (Exception e) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e); + } + String mess = LocalizedMessage.getLocalizedMessage("build.exception.message", this.referenceModel, this.localeName); + throw new BaseException(mess); + } + } + + public RowData remoteInvokePackageMethod(String managerName, String methodName, Map params) { + try { + return remoteInvokePackageMethodPri(managerName, methodName, params); + } catch (Exception e) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e); + } + String mess = LocalizedMessage.getLocalizedMessage("remoteInvokePackageMethod.exception.message", this.referenceModel, this.localeName); + throw new BaseException(mess); + } + } + + public RowData remoteInvokePackageMethodPri(String managerName, String methodName, Map params) throws Exception { + Object manager = this.ac.getBean(managerName); + Object result = null; + try { + Method method = manager.getClass().getMethod(methodName, Map.class); + result = method.invoke(manager, params); + } catch (IllegalAccessException e) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e); + } + } catch (IllegalArgumentException e2) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e2); + } + } catch (NoSuchMethodException e3) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e3); + } + } catch (SecurityException e4) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e4); + } + } catch (InvocationTargetException e5) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e5); + } + } + return (RowData) result; + } + + public InitTransObject remoteInvokeMethod(String managerName, String methodName, Map params) { + try { + InitTransObject o = new InitTransObject(); + Object result = remoteInvokeMethodPri(managerName, methodName, params); + o.setValue(result); + return o; + } catch (Exception e) { + String mess = LocalizedMessage.getLocalizedMessage("remoteInvokeMethod.exception.message", this.referenceModel, this.localeName); + throw new BaseException(mess); + } + } + + private Object remoteInvokeMethodPri(String managerName, String methodName, Map params) throws Exception { + Object manager = this.ac.getBean(managerName); + Method appropriateMethod = null; + boolean includeParam = true; + Method[] methods = manager.getClass().getMethods(); + int length = methods.length; + int i = 0; + while (true) { + if (i < length) { + Method method = methods[i]; + if (!method.getName().equals(methodName) || method.getParameterTypes().length != 1 || !method.getParameterTypes()[0].isAssignableFrom(Map.class)) { + i++; + } else { + appropriateMethod = method; + includeParam = true; + break; + } + } else { + break; + } + } + if (appropriateMethod == null) { + Method[] methods2 = manager.getClass().getMethods(); + int length2 = methods2.length; + int i2 = 0; + while (true) { + if (i2 < length2) { + Method method2 = methods2[i2]; + if (!method2.getName().equals(methodName) || method2.getParameterTypes().length != 0) { + i2++; + } else { + appropriateMethod = method2; + includeParam = false; + break; + } + } else { + break; + } + } + } + if (appropriateMethod == null) { + throw new EnergyServerRuntimeException("Can not find method [" + methodName + "] in manager [" + manager + "] with parameters length=0 OR parameter type is map"); + } + Object result = null; + try { + if (includeParam) { + result = appropriateMethod.invoke(manager, params); + } else { + result = appropriateMethod.invoke(manager, new Object[0]); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e2) { + e2.printStackTrace(); + } catch (InvocationTargetException e3) { + e3.printStackTrace(); + } + return result; + } + + public DataSourceParamUtil getDataSourceParamUtil() { + return this.dataSourceParamUtil; + } + + public void setDataSourceParamUtil(DataSourceParamUtil dataSourceParamUtil) { + this.dataSourceParamUtil = dataSourceParamUtil; + } + + private String parseQueryRef(String rawHql, Map clientParams, Map otherParams) { + String substringBetween = StringUtils.substringBetween(rawHql, "${", "}"); + while (true) { + String temp = substringBetween; + if (temp != null) { + Object value = clientParams.get(temp); + if (value == null || "".equals(value.toString())) { + if (temp.endsWith(".id")) { + otherParams.put(temp, new Long(0L)); + clientParams.put(temp, new Long(0L)); + } else { + otherParams.put(temp, ""); + clientParams.put(temp, "temp"); + } + } + rawHql = StringUtils.replace(rawHql, "${" + temp + "}", ":" + temp); + substringBetween = StringUtils.substringBetween(rawHql, "${", "}"); + } else { + return rawHql; + } + } + } + + public RowData[] remoteComplexQuery(String hql, Map params) { + return remoteQuery(hql, params); + } + + private String fomateHibernateHql(String hql, Map params) { + String substringBetween = StringUtils.substringBetween(hql, "{", "}"); + while (true) { + String _hql = substringBetween; + if (!StringUtils.isNotEmpty(_hql) || StringUtils.contains(hql, "${" + _hql + "}")) { + break; + } + hql = StringUtils.replace(hql, "{" + _hql + "}", ":" + _hql); + substringBetween = StringUtils.substringBetween(hql, "{", "}"); + } + return hql; + } + + private String getIntercepterName(Map params) { + String inter; + if (params.get("page_Id") != null && params.get("input_Id") != null) { + String pageId = params.remove("page_Id").toString(); + String inputId = params.remove("input_Id").toString(); + UniConfig config = (UniConfig) this.ac.getBean("uniConfig"); + Page page = config.getPage(this.referenceModel, pageId); + if (page == null) { + return null; + } + Assert.notNull(page, "page is not exist by id=" + pageId); + UI ui = page.getUIById(inputId); + if (ui == null) { + return null; + } + Assert.notNull(ui, "ui is not exist by id=" + inputId); + if ((ui instanceof ComplexComponent) && (inter = ((ComplexComponent) ui).getIntercepter()) != null) { + return inter; + } + return null; + } + return null; + } + + public RowData[] remoteQuery(String hql, Map params) { + String inter = getIntercepterName(params); + TableConfig tableConfig = (TableConfig) params.get("tableConfig"); + if (tableConfig != null) { + params.remove("tableConfig"); + } + try { + List result = this.valueListQueryManager.query(normalizeHqlAndParams(fomateHibernateHql(parseHql(removeHqlWithNullParam(convertGlobalParamToHql2(hql, params), params)), params), params), params); + RowData[] rd = buildRowData(tableConfig, result); + if (inter != null) { + AfterReturnIntercepter intercepter = (AfterReturnIntercepter) this.ac.getBean(inter); + rd = intercepter.afterReturn(rd); + } + return rd; + } catch (Exception e) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e); + } + String mess = LocalizedMessage.getLocalizedMessage("remoteQuery.exception.message", this.referenceModel, this.localeName); + throw new RemoteQueryException(mess); + } + } + + private String formateHql(String hql) { + String hqlStatement = hql; + int leftToenailIndex = hqlStatement.indexOf("("); + if (leftToenailIndex != -1) { + hqlStatement = StringUtils.replace(hqlStatement, "(", " ( "); + } + int rightToenailIndex = hqlStatement.indexOf(")"); + if (rightToenailIndex != -1) { + hqlStatement = StringUtils.replace(hqlStatement, ")", " ) "); + } + int enterIndex = hqlStatement.indexOf("\n"); + if (enterIndex != -1) { + hqlStatement = StringUtils.replace(hqlStatement, "\n", " \n"); + } + return hqlStatement; + } + + private String parseHql(String hql) { + String hqlStatement = hql; + String substringBetween = StringUtils.substringBetween(hqlStatement, "/~", "~/"); + while (true) { + String simple = substringBetween; + if (!StringUtils.isEmpty(simple)) { + String inputUIId = StringUtils.substringBetween(simple, "{", "}"); + String simple2 = StringUtils.replace(simple, "{" + inputUIId + "}", ":" + inputUIId + " "); + int andIndex = simple2.toUpperCase().indexOf(":") + 1; + hqlStatement = StringUtils.replace(hqlStatement, "/~" + simple + "~/", simple2.substring(andIndex, simple2.length())); + substringBetween = StringUtils.substringBetween(hqlStatement, "/~", "~/"); + } else { + return formateHql(hqlStatement); + } + } + } + + private String normalizeHqlAndParams(String rawHql, Map params) { + if (this.logger.isDebugEnabled()) { + this.logger.debug("Raw Hql:" + rawHql + ",query parameters:" + params); + } + HashMap hashMap = new HashMap(); + String rawHql2 = parseQueryRef(rawHql, params, hashMap); + List hqlParams = parseHqlParams(rawHql2); + HashMap hashMap2 = new HashMap(); + for (String param : hqlParams) { + Object value = params.get(param); + if (value == null || value.equals("")) { + rawHql2 = removeParamFromHql(rawHql2, param); + } else { + hashMap2.put(param, value); + } + } + params.clear(); + params.putAll(hashMap2); + params.putAll(hashMap); + HashMap hashMap3 = new HashMap(); + Iterator it = params.keySet().iterator(); + while (it.hasNext()) { + String key = (String) it.next(); + if (key.indexOf(".") != -1) { + Object value2 = params.get(key); + String newKey = StringUtils.replace(key, ".", ""); + hashMap3.put(newKey, value2); + rawHql2 = StringUtils.replace(rawHql2, ":" + key, ":" + newKey); + it.remove(); + } + } + params.putAll(hashMap3); + if (this.logger.isDebugEnabled()) { + this.logger.debug("HintDB Hql:" + rawHql2); + this.logger.debug("Parameters:" + params); + } + return rawHql2; + } + + private List parseHqlParams(String rawHql) { + List result = new ArrayList<>(); + StringTokenizer tokenizer = new StringTokenizer(rawHql); + while (tokenizer.hasMoreTokens()) { + String token = tokenizer.nextToken(); + if (token.indexOf(":") != -1) { + int index = token.indexOf(":"); + result.add(token.substring(index + 1)); + } + } + return result; + } + + private String removeParamFromHql(String rawHql, Object key) { + String param = ":" + ((String) key); + int paramIndex = rawHql.indexOf(param); + if (paramIndex == -1) { + return rawHql; + } + int andIndex = rawHql.toUpperCase().lastIndexOf("AND", paramIndex); + if (andIndex == -1) { + return rawHql; + } + String tobeRemoveString = rawHql.substring(andIndex, paramIndex + param.length()); + if (this.logger.isDebugEnabled()) { + this.logger.debug("[" + tobeRemoveString + "] removed from " + rawHql); + } + return StringUtils.replace(rawHql, tobeRemoveString, ""); + } + + public TableConfig scrollableQuery(TableConfig tableConfig, Map queryParams) { + String inter = getIntercepterName(queryParams); + Map pageParams = tableConfig.getParams(); + pageParams.put("pagingPage", new StringBuilder().append(tableConfig.getCurrentPage()).toString()); + if (!pageParams.containsKey("pagingNumberPer")) { + pageParams.put("pagingNumberPer", new StringBuilder().append(tableConfig.getPagingNumberPer()).toString()); + } + String hql = tableConfig.getHql(); + Assert.notNull(hql, String.valueOf(tableConfig.getPageId()) + "'s hql is null!"); + TableConfig tableConfig2 = buildScrollHqlGrid(tableConfig, normalizeHqlAndParams(fomateHibernateHql(parseHql(removeHqlWithNullParam2(convertGlobalParamToHql2(hql, queryParams), queryParams)), queryParams), queryParams), pageParams, queryParams); + if (inter != null) { + AfterReturnIntercepter intercepter = (AfterReturnIntercepter) this.ac.getBean(inter); + tableConfig2 = intercepter.afterReturn(tableConfig2); + } + return tableConfig2; + } + + public UniConfig getUniConfig() { + return this.uniConfig; + } + + public void setUniConfig(UniConfig uniConfig) { + this.uniConfig = uniConfig; + } + + public String convertGlobalParamToHql2(String hql, Map params) { + String value; + String substringBetween = StringUtils.substringBetween(hql, "/~", "~/"); + while (true) { + String _hql = substringBetween; + if (StringUtils.isEmpty(_hql) || StringUtils.isEmpty(StringUtils.substringBetween(_hql, "#{", "}"))) { + break; + } + String sessionParam = StringUtils.substringBetween(_hql, "#{", "}"); + if (!StringUtils.isEmpty(sessionParam)) { + Object sessionValue = this.request.getSession().getAttribute(sessionParam); + if (sessionValue == null) { + sessionValue = this.uniConfig.getGlobalParam(sessionParam, this.referenceModel).getClientGlobal(); + } + if (sessionValue != null) { + if (!(sessionValue instanceof Entity)) { + if (sessionValue instanceof String) { + value = "'" + sessionValue.toString() + "'"; + } else { + value = sessionValue.toString(); + } + hql = StringUtils.replace(hql, "#{" + sessionParam + "}", value); + } else { + hql = StringUtils.replace(hql, "#{" + sessionParam + "}", ":" + sessionParam); + params.put(sessionParam, sessionValue); + } + StringUtils.replace(hql, "/~" + _hql + "~/", StringUtils.substring(_hql, _hql.indexOf(":") + 1)); + } else { + throw new EnergyServerRuntimeException("Session parameter [" + sessionParam + "] does contain corresponding value in session attribute"); + } + } + substringBetween = StringUtils.substringBetween(hql, "/~", "~/"); + } + String substringBetween2 = StringUtils.substringBetween(hql, "#{", "}"); + while (true) { + String sessionParam2 = substringBetween2; + if (!StringUtils.isEmpty(sessionParam2)) { + Object sessionValue2 = this.request.getSession().getAttribute(sessionParam2); + if (sessionValue2 == null) { + sessionValue2 = this.uniConfig.getGlobalParam(sessionParam2, this.referenceModel).getClientGlobal(); + } + if (sessionValue2 != null) { + if (!(sessionValue2 instanceof Entity)) { + String value2 = ""; + if (sessionValue2 instanceof String) { + value2 = "'" + sessionValue2.toString() + "'"; + } else if (sessionValue2 instanceof Collection) { + hql = StringUtils.replace(hql, "#{" + sessionParam2 + "}", "{" + sessionParam2 + "}"); + params.put(sessionParam2, sessionValue2); + } else { + value2 = sessionValue2.toString(); + } + hql = StringUtils.replace(hql, "#{" + sessionParam2 + "}", value2); + } else { + hql = StringUtils.replace(hql, "#{" + sessionParam2 + "}", ":" + sessionParam2); + params.put(sessionParam2, sessionValue2); + } + substringBetween2 = StringUtils.substringBetween(hql, "#{", "}"); + } else { + throw new EnergyServerRuntimeException("Session parameter [" + sessionParam2 + "] does contain corresponding value in session attribute"); + } + } else { + if (this.logger.isDebugEnabled()) { + this.logger.debug("Convert session parameters into HQL:" + hql); + } + return hql; + } + } + } + + public Map remoteInitListener(List listener, Map params) throws BaseException { + Map result = new HashMap<>(); + Iterator i = listener.iterator(); + while (i.hasNext()) { + InitListenerContext context = (InitListenerContext) i.next(); + try { + result.put(context.getId(), remoteInvokeMethodPri(context.getManagerName(), context.getMethodName(), params)); + } catch (Exception e) { + if (this.logger.isErrorEnabled()) { + this.logger.error(e); + } + } + } + return result; + } + + public TableConfig customRemoteQuery(String hql, TableConfig tableConfig, Map params) throws BaseException { + Map pageParams = tableConfig.getParams(); + pageParams.put("pagingPage", new StringBuilder().append(tableConfig.getCurrentPage()).toString()); + if (!pageParams.containsKey("pagingNumberPer")) { + pageParams.put("pagingNumberPer", "10"); + } + ValueList valueList = this.valueListQueryManager.scrollableQuery(normalizeHqlAndParams(fomateHibernateHql(parseHql(removeHqlWithNullParam(convertGlobalParamToHql2(hql, params), params)), params), params), pageParams, params); + if (valueList == null) { + throw new EnergyServerRuntimeException("Cann't query datas from DataBase! "); + } + initGridInfo(tableConfig, valueList); + return tableConfig; + } + + public Map remoteInitCompexUI(Map params) throws BaseException { + Map result = new HashMap<>(); + for (Object obj : params.keySet()) { + String key = obj.toString(); + HqlParam value = (HqlParam) params.get(key); + result.put(key, remoteComplexQuery(value.getHql(), value.getParams())); + } + return result; + } + + public Map remoteQueryComplexUI(Map params) throws BaseException { + Map result = new HashMap<>(); + for (Object obj : params.keySet()) { + String key = obj.toString(); + Map value = (Map) params.get(key); + String hql = value.keySet().iterator().next().toString(); + result.put(key, remoteQuery(hql, (Map) value.get(hql))); + } + return result; + } + + public ValueListQueryManager getValueListQueryManager() { + return this.valueListQueryManager; + } + + public void setValueListQueryManager(ValueListQueryManager valueListQueryManager) { + this.valueListQueryManager = valueListQueryManager; + } +} diff --git a/src/webapp/WEB-INF/classes/config/origen/inventory/maintainInventoryLogPage.xml b/src/webapp/WEB-INF/classes/config/origen/inventory/maintainInventoryLogPage.xml index 9c6515b..f926cd6 100644 --- a/src/webapp/WEB-INF/classes/config/origen/inventory/maintainInventoryLogPage.xml +++ b/src/webapp/WEB-INF/classes/config/origen/inventory/maintainInventoryLogPage.xml @@ -80,10 +80,25 @@ from WarehouseArea warehouseArea where 1=1 and warehouseArea.disabled=false order by warehouseArea.name]]> - + + + + = {beginDate} ~/ - /~endDate: AND CONVERT(varchar(100), inventoryLog.occurTime, 23)>= {beginDate} and CONVERT(varchar(100), inventoryLog.occurTime, 23)<= {endDate} ~/ - ) + /~beginDate: AND inventoryLog.occurTime >= {beginDate} ~/ + /~endDate: AND inventoryLog.occurTime <= {endDate} ~/ ORDER BY inventoryLog.id DESC]]> + autoQuery="false">