⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findservices.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                subMap2 = new HashMap();
                subMap.put(fieldPair, subMap2);
            }
            subMap2.put(fieldMode, fieldValue);
        }

        // Now use only the values that correspond to entity fields to build
        //   an EntityConditionList
        GenericDelegator delegator = dctx.getDelegator();

        GenericValue entityValue = delegator.makeValue(entityName, new HashMap());

        ModelEntity modelEntity = entityValue.getModelEntity();
        List keys = modelEntity.getAllFieldNames();
        Iterator iter = keys.iterator();
        EntityOperator entOp = EntityOperator.AND;
        EntityExpr cond = null;
        ArrayList tmpList = new ArrayList();
        String opString = null;
        int count = 0;
        while (iter.hasNext()) {
            fieldName = (String) iter.next();
            subMap = (HashMap) normalizedFields.get(fieldName);
            if (subMap == null) {
                continue;
            }

            subMap2 = (HashMap) subMap.get("fld0");
            opString = (String) subMap2.get("op");

            if (opString != null) {
                if (opString.equals("contains")) {
                    fieldOp = (EntityOperator) entityOperators.get("like");

                } else if (opString.equals("empty")) {
                    fieldOp = (EntityOperator) entityOperators.get("equals");
                } else {
                    fieldOp = (EntityOperator) entityOperators.get(opString);
                }
            } else {
                fieldOp = (EntityOperator) entityOperators.get("equals");
            }

            fieldValue = (String) subMap2.get("value");
            if (fieldValue == null) {
                continue;
            }

            if (opString != null) {
                if (opString.equals("contains")) {
                    fieldOp = (EntityOperator) entityOperators.get("like");
                    fieldValue = "%" + fieldValue + "%";
                } else if (opString.equals("empty")) {
                    fieldOp = (EntityOperator) entityOperators.get("equals");
                    fieldValue = null;
                } else if (opString.equals("like")) {
                    fieldOp = (EntityOperator) entityOperators.get("like");
                    fieldValue += "%";
                } else if (opString.equals("greaterThanFromDayStart")) {
                    fieldValue = dayStart(fieldValue, 0);
                    fieldOp = (EntityOperator) entityOperators.get("greaterThan");
                } else if (opString.equals("sameDay")) {
                    String timeStampString = fieldValue;
                    fieldValue = dayStart(timeStampString, 0);
                    fieldOp = (EntityOperator) entityOperators.get("greaterThan");
    
                    // Set up so next part finds ending conditions for same day
                    subMap2 = (HashMap) subMap.get("fld1");
                    if (subMap2 == null) {
                        subMap2 = new HashMap();
                        subMap.put("fld1", subMap2);
                    }
                    String endOfDay = dayStart(timeStampString, 1);
                    subMap2.put("value", endOfDay);
                    subMap2.put("op", "lessThan");
                } else {
                    fieldOp = (EntityOperator) entityOperators.get(opString);
                }
            } else {
                fieldOp = (EntityOperator) entityOperators.get("equals");
            }

            cond = new EntityExpr(fieldName, (EntityComparisonOperator) fieldOp, fieldValue);
            tmpList.add(cond);
            count++;

            // Repeat above operations if there is a "range" - second value
            subMap2 = (HashMap) subMap.get("fld1");
            if (subMap2 == null) {
                continue;
            }
            opString = (String) subMap2.get("op");

            if (opString != null) {
                if (opString.equals("contains")) {
                    fieldOp = (EntityOperator) entityOperators.get("like");
                } else if (opString.equals("empty")) {
                    fieldOp = (EntityOperator) entityOperators.get("equals");
                } else {
                    fieldOp = (EntityOperator) entityOperators.get(opString);
                }
            } else {
                fieldOp = (EntityOperator) entityOperators.get("equals");
            }

            fieldValue = (String) subMap2.get("value");
            if (fieldValue == null) {
                continue;
            }
            if (opString.equals("like")) {
                fieldValue += "%";
            } else if (opString.equals("contains")) {
                fieldValue += "%" + fieldValue + "%";
            } else if (opString.equals("empty")) {
                fieldOp = (EntityOperator) entityOperators.get("equals");
                fieldValue = null;
            } else if (opString.equals("upToDay")) {
                fieldValue = dayStart(fieldValue, 0);
                fieldOp = (EntityOperator) entityOperators.get("lessThan");
            } else if (opString.equals("upThruDay")) {
                fieldValue = dayStart(fieldValue, 1);
                fieldOp = (EntityOperator) entityOperators.get("lessThan");
            }
            // String rhs = fieldValue.toString();
            cond = new EntityExpr(fieldName, (EntityComparisonOperator) fieldOp, fieldValue);
            tmpList.add(cond);
        }
        EntityConditionList exprList = new EntityConditionList(tmpList, (EntityJoinOperator) entOp);
        EntityListIterator listIt = null;

        if (count > 0) {
            /* Retrieve entities  - an iterator over all the values*/
            try {
                listIt = delegator.findListIteratorByCondition(entityName, exprList,
                        null, null, null, new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, false));
            } catch (GenericEntityException e) {
                return ServiceUtil.returnError("Error finding iterator: " + e.getMessage());
            }
        } else {
            try {
                /*
                List pkList = delegator.getModelEntity(entityName).getPkFieldNames();
                String pkName = (String)pkList.get(0);
                EntityExpr pkExpr = new EntityExpr(pkName, EntityOperator.LIKE, "%");
                */
                listIt = delegator.findListIteratorByCondition(entityName, null,
                        null, null, null, new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, false));
            } catch (GenericEntityException e) {
                return ServiceUtil.returnError("Error finding all: " + e.getMessage());
            }
        }

        Map results = ServiceUtil.returnSuccess();
        results.put("listIt", listIt);
        return results;
    }

    private static String dayStart(String timeStampString, int daysLater) {
        String retValue = null;
        Timestamp ts = null;
        Timestamp startTs = null;
        try {
            ts = Timestamp.valueOf(timeStampString);
        } catch (IllegalArgumentException e) {
            timeStampString += " 00:00:00.000";
            try {
                ts = Timestamp.valueOf(timeStampString);
            } catch (IllegalArgumentException e2) {
                return retValue;
            }
        }
        startTs = UtilDateTime.getDayStart(ts, daysLater);
        retValue = startTs.toString();
        return retValue;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -