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

📄 findparty.bsh

📁 国外的一套开源CRM
💻 BSH
📖 第 1 页 / 共 2 页
字号:
/*
 *  Copyright (c) 2001-2004 The Open For Business Project - www.ofbiz.org
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a
 *  copy of this software and associated documentation files (the "Software"),
 *  to deal in the Software without restriction, including without limitation
 *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
 *  and/or sell copies of the Software, and to permit persons to whom the
 *  Software is furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included
 *  in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
 *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
 *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *@author     Andy Zeneski (jaz@ofbiz.org)
 *@version    $Revision: 1.13 $
 *@since      3.0
 */

import java.util.*;
import java.sql.Timestamp;
import org.ofbiz.base.util.*;
import org.ofbiz.entity.*;
import org.ofbiz.entity.util.*;
import org.ofbiz.entity.model.*;
import org.ofbiz.entity.condition.*;
import org.ofbiz.securityext.login.*;
import org.ofbiz.common.*;

delegator = request.getAttribute("delegator");
extraInfo = request.getParameter("extInfo");

externalLoginKey = LoginEvents.getExternalLoginKey(request);
externalKeyParam = externalLoginKey == null ? "" : "&externalLoginKey=" + externalLoginKey;
context.put("externalKeyParam",externalKeyParam);

// get the role types
roleTypes = delegator.findAll("RoleType", UtilMisc.toList("description"));
context.put("roleTypes", roleTypes);

// current role type
currentRoleTypeId = request.getParameter("roleTypeId");
if (currentRoleTypeId != null && currentRoleTypeId.length() > 0) {
    currentRole = delegator.findByPrimaryKeyCache("RoleType", UtilMisc.toMap("roleTypeId", currentRoleTypeId));
    context.put("currentRole", currentRole);
}

// current state
currentStateGeoId = request.getParameter("stateProvinceGeoId");
if (currentStateGeoId != null && currentStateGeoId.length() > 0) {
    currentStateGeo = delegator.findByPrimaryKeyCache("Geo", UtilMisc.toMap("geoId", currentStateGeoId));
    context.put("currentStateGeo", currentStateGeo);
}

// set the page parameters
viewIndex = 1;
try {
    viewIndex = Integer.valueOf((String) request.getParameter("VIEW_INDEX")).intValue();
} catch (Exception e) {
    viewIndex = 1;
}
context.put("viewIndex", viewIndex);

viewSize = 20;
try {
    viewSize = Integer.valueOf((String) request.getParameter("VIEW_SIZE")).intValue();
} catch (Exception e) {
    viewSize = 20;
}
context.put("viewSize", viewSize);

// get the lookup flag
lookupFlag = request.getParameter("lookupFlag");

// blank param list
paramList = "";

partyList = null;
partyListSize = 0;
lowIndex = 0;
highIndex = 0;

if (lookupFlag != null && lookupFlag.equalsIgnoreCase("Y")) {
    showAll = request.getParameter("showAll") != null ? request.getParameter("showAll") : "N";
    extInfo = request.getParameter("extInfo");
    paramList = paramList + "&lookupFlag=" + lookupFlag + "&showAll=" + showAll + "&extInfo=" + extInfo;

    // error message holder
    lookupErrorMessage = null;

    // create the dynamic view entity
    dynamicView = new DynamicViewEntity();

    // default view settings
    dynamicView.addMemberEntity("PT", "Party");
    dynamicView.addAlias("PT", "partyId");
    dynamicView.addAlias("PT", "partyTypeId");
    dynamicView.addRelation("one-nofk", "", "PartyType", ModelKeyMap.makeKeyMapList("partyTypeId"));
    dynamicView.addRelation("many", "", "UserLogin", ModelKeyMap.makeKeyMapList("partyId"));

    // define the main condition & expression list
    andExprs = new ArrayList();
    mainCond = null;

    // check for a partyId (happens in some browsers)
    partyId = request.getParameter("partyId");
    if (partyId != null && partyId.length() > 0) {
        paramList = paramList + "&partyId=" + partyId;
        andExprs.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));
    }

    // ----
    // UserLogin Fields
    // ----

    // filter on user login
    userLoginId = request.getParameter("userLoginId");
    if (userLoginId != null && userLoginId.length() > 0) {
        paramList = paramList + "&userLoginId=" + userLoginId;

        // modify the dynamic view
        dynamicView.addMemberEntity("UL", "UserLogin");
        dynamicView.addAlias("UL", "userLoginId");
        dynamicView.addViewLink("PT", "UL", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId"));

        // add the expr
        andExprs.add(new EntityExpr("userLoginId", true, EntityOperator.LIKE, "%"+userLoginId+"%", true));
    }

    // ----
    // PartyGroup Fields
    // ----

    // filter on groupName
    groupName = request.getParameter("groupName");
    if (groupName != null && groupName.length() > 0) {
        paramList = paramList + "&groupName=" + groupName;

        // modify the dynamic view
        dynamicView.addMemberEntity("PG", "PartyGroup");
        dynamicView.addAlias("PG", "groupName");
        dynamicView.addViewLink("PT", "PG", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId"));

        // add the expr
        andExprs.add(new EntityExpr("groupName", true, EntityOperator.LIKE, "%"+groupName+"%", true));
    }

    // ----
    // Person Fields
    // ----

    // get the params
    firstName = request.getParameter("firstName");
    lastName = request.getParameter("lastName");

    // modify the dynamic view
    if ((firstName != null && firstName.length() > 0) || (lastName != null && lastName.length() > 0)) {
        dynamicView.addMemberEntity("PE", "Person");
        dynamicView.addAlias("PE", "firstName");
        dynamicView.addAlias("PE", "lastName");
        dynamicView.addViewLink("PT", "PE", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId"));
    }

    // filter on firstName
    if (firstName != null && firstName.length() > 0) {
        paramList = paramList + "&firstName=" + firstName;
        andExprs.add(new EntityExpr("firstName", true, EntityOperator.LIKE, "%"+firstName+"%", true));
    }

    // filter on lastName
    if (lastName != null && lastName.length() > 0) {
        paramList = paramList + "&lastName=" + lastName;
        andExprs.add(new EntityExpr("lastName", true, EntityOperator.LIKE, "%"+lastName+"%", true));
    }

    // ----
    // RoleType Fields
    // ----

    // filter on role member
    roleType = request.getParameter("roleTypeId");
    if (roleType != null && !"ANY".equals(roleType)) {
        paramList = paramList + "&roleTypeId=" + roleType;

        // add role to view
        dynamicView.addMemberEntity("PR", "PartyRole");
        dynamicView.addAlias("PR", "roleTypeId");
        dynamicView.addViewLink("PT", "PR", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId"));

        // add the expr
        andExprs.add(new EntityExpr("roleTypeId", EntityOperator.EQUALS, roleType));
    }

⌨️ 快捷键说明

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