*/
public static void adjustWhereNode(Document doc , Node node){
Node envNode = XMLUtil.getSingleNode(doc, "query/env");
String idStr = XMLUtil.getAttribute(node, "id");
UUID id = DataAccessFactory.getInstance().createUUID(idStr);
String type = XMLUtil.getAttribute(node, "type");
List<Flow> allFlows = null;
//where fields
Node whereNode = XMLUtil.getSingleNode(node, "where");
if(whereNode != null){
List<Node> whereFieldNodeList = XMLUtil.getNodes(whereNode, "field");
for(Node whereFieldNode : whereFieldNodeList){
String fieldId = XMLUtil.getAttribute(whereFieldNode, "id");
String fieldMethod = XMLUtil.getAttribute(whereFieldNode, "method");
String fieldType = XMLUtil.getAttribute(whereFieldNode, "type");
String fieldDataType = XMLUtil.getAttribute(whereFieldNode, "dataType");
String fieldValue = whereFieldNode.getTextContent();
if(fieldValue.startsWith("$") && fieldValue.endsWith("$")){
List<Node> defineNodeList = XMLUtil.getNodes(envNode, fieldValue.substring(1, fieldValue.length() - 1));
if(defineNodeList.size() == 0){
continue;
}
if(defineNodeList.size() == 1){
whereFieldNode.setTextContent(defineNodeList.get(0).getTextContent());
}
else{
Node leftNode = doc.createElement("condition");
leftNode.setTextContent("(");
whereNode.insertBefore(leftNode, whereFieldNode);
if(fieldMethod.equals("!=")){
Node newFieldNode = whereFieldNode.cloneNode(true);
XMLUtil.setAttribute(newFieldNode, "method", "is null");
whereNode.insertBefore(newFieldNode, whereFieldNode);
Node orNode = doc.createElement("condition");
orNode.setTextContent("or");
whereNode.insertBefore(orNode, whereFieldNode);
}
for(int i = 0; i < defineNodeList.size(); i++){
if(i > 0){
Node relationNode = doc.createElement("condition");
if(fieldMethod.equals("=")){
relationNode.setTextContent("or");
}
else if(fieldMethod.equals("!=")){
relationNode.setTextContent("and");
}
whereNode.insertBefore(relationNode, whereFieldNode);
}
Node newFieldNode = whereFieldNode.cloneNode(true);
newFieldNode.setTextContent(defineNodeList.get(i).getTextContent());
whereNode.insertBefore(newFieldNode, whereFieldNode);
}
//(
Node rightNode = doc.createElement("condition");
rightNode.setTextContent(")");
whereNode.insertBefore(rightNode, whereFieldNode);
whereNode.removeChild(whereFieldNode);
}
}
if(fieldId.equals("status_id") && (fieldValue.equals("[逻辑开始]") || fieldValue.equals("[逻辑关闭]"))){
StringBuffer statusIdStrb = new StringBuffer();
List<Flow> flowList = new ArrayList<Flow>();
if(type.equals("tt")){
if (allFlows == null) {
allFlows = FlowCache.getInstance().getAll();
}
if (allFlows == null) {
continue;
}
flowList.addAll(allFlows);
}else if(type.equals("t")){
Template template = TemplateCache.getInstance().get(id);
if(template == null){
continue;
}
Flow flow = FlowCache.getInstance().get(template.getFlowId());
if (flow == null) {
continue;
}
flowList.add(flow);
}
for(Flow flow : flowList){
if(flow == null){
continue;
}
if(fieldValue.equals("[逻辑开始]") && flow.getBeginStats() != null){
for(Stat stat : flow.getBeginStats()){
if(statusIdStrb.length() > 0){
statusIdStrb.append(",");
}
statusIdStrb.append(stat.getId());
}
}
else if(fieldValue.equals("[逻辑关闭]") && flow.getEndStats() != null){
for(Stat stat : flow.getEndStats()){
if(statusIdStrb.length() > 0){
statusIdStrb.append(",");
}
statusIdStrb.append(stat.getId());
}
}
}
if(statusIdStrb.length() == 0){
continue;
}
if(fieldMethod.equals("=")){
XMLUtil.setAttribute(whereFieldNode, "method", "in");
}
else if(fieldMethod.equals("!=")){
XMLUtil.setAttribute(whereFieldNode, "method", "not in");
}
whereFieldNode.setTextContent(statusIdStrb.toString());
}
//创建人 指派人可以指派给角色
if((fieldId.equals("create_user") || fieldId.equals("assign_user") || fieldId.equals("log_create_user")) && (fieldValue.startsWith("role_"))){
String roleIdStr = fieldValue.substring(5);
if (!CommonUtil.isPosNum(roleIdStr))
continue;
StringBuffer roleUsers = new StringBuffer();
if (type.equals("t")) {
Template template = TemplateCache.getInstance().get(id);
if(template == null){
continue;
}
Flow flow = FlowCache.getInstance().get(template.getFlowId());
if (flow == null) {
continue;
}
UUID roleId = DataAccessFactory.getInstance().createUUID(roleIdStr);
Set<Right> allRoleRight = flow.queryRightsByRole(roleId);
for (Right right : allRoleRight) {
roleUsers.append(roleUsers.length() > 0 ? "," : "").append(right.getUsername());
}