String type = XMLUtil.getSingleNode(rootNode, "type").getTextContent();
if (type.equals("task")) {
return null;
}
String templateIdStr = XMLUtil.getSingleNode(rootNode, "templateId").getTextContent();
UUID templateId = null;
templateId = DataAccessFactory.getInstance().createUUID(templateIdStr);
String startTimeStr = XMLUtil.getSingleNode(rootNode, "timeRange/startTime").getTextContent();
String endTimeStr = XMLUtil.getSingleNode(rootNode, "timeRange/endTime").getTextContent();
String timeType = XMLUtil.getSingleNode(rootNode, "timeRange/timeType").getTextContent();
if(timeType != null && !timeType.equals("")){
Pair<String, String> timePair = DataFilterMemory.getTimeSpan(timeType);
if (timePair != null) {
startTimeStr = timePair.getFirst();
endTimeStr = timePair.getSecond();
}
}
Timestamp startTimestamp = null;
Timestamp endTimestamp = null;
try {
if (startTimeStr != null && !startTimeStr.equals("")) {
startTimestamp = Timestamp.valueOf(startTimeStr);
}
if (endTimeStr != null && !endTimeStr.equals("")) {
endTimestamp = Timestamp.valueOf(endTimeStr);
}else {
endTimestamp = new Timestamp(System.currentTimeMillis());
}
} catch (Exception e) {
}
//获取过滤器查询where条件、
Node whereNode = XMLUtil.getSingleNode(rootNode, "queryCondition/where");
//判断是否需要从日志中查询
boolean isCurrent = FilterUtil.getIsQueryLog(whereNode);
String whereStr = FilterUtil.getWhereConditionStr(doc,whereNode,isCurrent,templateIdStr,username);
Set<String> allIdSet = new HashSet<String>(); //所有id集合
if (type.equals("person")) {
String roleActionIds = XMLUtil.getSingleNode(rootNode, "person/roleActionIds").getTextContent();
String containCurAssignStr = XMLUtil.getSingleNode(rootNode, "person/containCurAssign").getTextContent();
boolean containCurAssign = (containCurAssignStr != null && containCurAssignStr.equals("yes")) ? true:false;
String dataLogTable = TableRuleManager.getInstance().getDataLogTableName(templateId);
whereStr = whereConProcess(whereStr);
StringBuffer logActionIdBuffer = new StringBuffer();
String[] actionArr = roleActionIds.split(",");
if (actionArr == null || actionArr.length == 0) {
return null;
}
for (String actionId : actionArr) {
logActionIdBuffer.append(logActionIdBuffer.length() > 0 ? "," : "").append("'" + actionId + "'");
}
StringBuffer sqlBuffer = new StringBuffer();
sqlBuffer.append("select dataid from ").append(dataLogTable).append(" where is_valid=1 and logcreateUser='").append(statisticVal).append("' and templateId =").append(templateId.getValue()).append(" and ").append(whereStr).append(" and logActionId in (")
.append(logActionIdBuffer.toString()).append(")");
if (startTimestamp != null) {
sqlBuffer.append(" and logcreateTime >= '"+startTimestamp.toString() + "'");
}
if (endTimestamp != null) {
sqlBuffer.append(" and logcreateTime <= '"+endTimestamp.toString() + "'");
}
List<Map<String, String>> allIdMap = DbPoolConnection.getInstance().getResultSetListBySql(sqlBuffer.toString());
for (Map<String, String> map : allIdMap) {
allIdSet.add(map.get("dataid"));
}
if (containCurAssign) {
//包含当前指派数据
try {
String dataTable = TableRuleManager.getInstance().getDataTableName(templateId);
//查询当前指派的数据
sqlBuffer = new StringBuffer();
sqlBuffer.append("select id from ").append(dataTable).append(" where is_valid=1 and assignUser = '").append(statisticVal).append("' and templateId=").append(templateId.getValue()).append(" and ").append(whereStr);
if (startTimestamp != null) {
sqlBuffer.append(" and createTime >= '"+startTimestamp.toString() + "'");
}
if (endTimestamp != null) {
sqlBuffer.append(" and createTime <= '"+endTimestamp.toString() + "'");
}
allIdMap = DbPoolConnection.getInstance().getResultSetListBySql(sqlBuffer.toString());
for (Map<String, String> map : allIdMap) {
allIdSet.add(map.get("id"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}else {
String modelFieldIdStr = "";
if (type.equals("model")) {
modelFieldIdStr = XMLUtil.getSingleNode(rootNode, "model/modelfieldId").getTextContent();
}else if (type.equals("public")) {
modelFieldIdStr = "templateId";
}
String fieldColName = DataFilterMemory.getDbColName(modelFieldIdStr, templateId == null ? null : templateId.getValue());
fieldColName = fieldColName == null ? modelFieldIdStr : fieldColName;
List<String> tablesList = new ArrayList<String>();
if (templateId != null) {
tablesList.add(TableRuleManager.getInstance().getDataTableName(templateId));
}else {
tablesList.addAll(TableRuleManager.getInstance().getAllDataTables());
}
Set<String> queryFieldSet = new HashSet<String>();
//查询所有id;
queryFieldSet.add("id");
List<QueryCondition> queryConList = new ArrayList<QueryCondition>();
if (startTimestamp != null) {
queryConList.add(new QueryCondition("createTime",">=","'"+startTimestamp.toString() + "'"));
}
if (endTimestamp != null) {
queryConList.add(new QueryCondition("createTime","<=","'"+endTimestamp.toString() + "'"));
}
if (templateId != null) {
queryConList.add(new QueryCondition("templateId","=","'"+templateId.getValue() + "'"));
}
if (statisticVal.indexOf(",") != -1) {
StringBuffer queryValBuffer = new StringBuffer();