JEECG中的validform驗證ajaxurl的使用方法


validform驗證是一種非常方便的,實用的驗證方式

對於需要驗證后台數據的,validform是一個非常明智的選擇

validform的ajaxurl屬性能夠完美的實現:當輸入完成某一輸入框,就會調用后台方法進行驗證,如果符合要求就返回y,如果不符合要求就返回n

 

現在以添加鄉鎮信息為例作為講解:

業務需求:用戶錄入鄉鎮信息,包括鄉鎮編碼和鄉鎮名稱,每當輸入完成編號或名稱光標移開的時候,就要驗證編碼或者名稱是否在數據庫中已經存在,如果存在,那么就提示進行重新輸入,如果不存在就提示編碼或名稱可用

用戶界面:

前台頁面:

<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/back/main/include/baseInclude.jsp" %>
<html>
    <head>
        <title>個人設置</title>
        <meta name="menu" content="user" />
        <link href="${basePath}/common/css/table.css" rel="stylesheet" type="text/css" />
        <script src="${basePath}/common/js/validform.min.js" type="text/javascript" ></script>
        <script src="${basePath}/common/js/validform_datatype.js" type="text/javascript" ></script>
        <script src="${basePath}/back/user/js/dealerUser.js" type="text/javascript"></script>
    </head>
    
    <body style="text-align:left;">
        <input type="hidden" id="basePath" value="${basePath}"/>
        <h3 style="text-align:center;">個人設置</h3>
        <s:form name="myform" action="personalSettings.action" method="post" id="pageform">
            <table id="mytable" cellspacing="0" summary="個人設置">
            <caption>
                個人信息
                <a style="float:right;margin:0 -100px" href="javascript:history.go(-1);">返回</a>
            </caption>
                <tr>
                    <th scope="col" style="width:100px;text-align:right;" class="specalt">帳號:</th>
                    <td scope="col" class="alt" style="text-align: left;">
                        ${operatorUser.loginName}
                    </td>
                </tr>
                <tr>
                    <th scope="col" style="width:100px;text-align:right;" class="specalt">舊密碼:</th>
                    <td scope="col" class="alt" style="text-align: left;">
                        <input type="password" name="oldPass" nullmsg="請填寫密碼!" datatype="*6-20" errormsg="密碼范圍在6~20位之間!" ajaxurl="checkPassword.action" />
                    </td>
                </tr>
                <tr>
                    <th scope="col" style="width:100px;text-align:right;" class="specalt">密碼:</th>
                    <td scope="col" class="alt" style="text-align: left;">
                        <input type="password" name="operatorUser.password" id="password" nullmsg="請填寫密碼!" datatype="*6-20" errormsg="密碼范圍在6~20位之間!" ajaxurl="checkNewPassword.action" />
                    </td>
                </tr>
                <tr>
                    <th scope="col" style="width:100px;text-align:right;" class="specalt">確認密碼:</th>
                    <td scope="col" class="alt" style="text-align: left;">
                        <input type="password" nullmsg="請再輸入一次密碼!" recheck="operatorUser.password" datatype="*" />
                    </td>
                </tr>
                <tr>
                    <th scope="col" style="width:100px;text-align:right;" class="specalt">原授權碼:</th>
                    <td scope="col" class="alt" style="text-align: left;">
                        <input type="password" nullmsg="請填寫授權碼!" datatype="*6-20" errormsg="授權碼范圍在6~20位之間!" ajaxurl="checkAuthorizepwd.action" />
                    </td>
                </tr>
                <tr>
                    <th scope="col" style="width:100px;text-align:right;" class="specalt">授權碼:</th>
                    <td scope="col" class="alt" style="text-align: left;">
                        <input type="password" nullmsg="請填寫授權碼!" name="operatorUser.authorizepwd" datatype="*6-20" errormsg="授權碼范圍在6~20位之間!" />
                    </td>
                </tr>
                <tr>
                    <th scope="col" style="width:100px;text-align:right;" class="specalt">真實姓名:</th>
                    <td scope="col" class="alt" style="text-align: left;">
                        <input type="text" name="operatorUser.userName" id="userName" value="${operatorUser.userName}" nullmsg="請填寫真實姓名!" datatype="*" />
                    </td>
                </tr>
                <tr>
                    <th scope="col" style="width:100px;text-align:right;" class="specalt">email:</th>
                    <td scope="col" class="alt" style="text-align: left;">
                        <input type="text" name="operatorUser.email" id="email" value="${operatorUser.email}" nullmsg="請填寫郵箱信息!" datatype="e" errormsg="請填寫正確的郵箱地址!" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" onclick="return checkField();" value="確 定"/>
                        <input type="button" onclick="qxBtn();" value="取 消"/>
                    </td>
                </tr>
            </table>
        </s:form>
    </body>

</html>

 

后台代碼實現:

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.hsmpay.back.action.base.BackBaseAction;
import com.hsmpay.back.pojo.organization.Organization;
import com.hsmpay.back.pojo.system.Role;
import com.hsmpay.back.pojo.user.OperatorUser;
import com.hsmpay.back.service.organization.OrganizationService;
import com.hsmpay.back.service.system.RoleService;
import com.hsmpay.back.service.user.OperatorUserService;
import com.hsmpay.back.util.GlobalConstant;
import com.hsmpay.back.util.PageDown;
import com.hsmpay.common.util.MD5;

/**
 * 后台用戶action
 * @author 顏鈴璋
 * @version 1.0
 * @date 2012-11-28    
 */
@Controller("operatorUserAction")
@Scope("prototype")
public class OperatorUserAction extends BackBaseAction{
    private static final long serialVersionUID = -5319745710227353987L;
    static Logger log = Logger.getLogger(OperatorUserAction.class);
    private OperatorUser operatorUser;//jsp直接引用或傳參 操作員對象
    private List<OperatorUser> operatorUserList;
    private List<Role> roleList;//角色列表
    private List<Organization> organizationList;//后台操作員列表
    
    @Resource(name="roleService")
    private RoleService<Role,Long> roleService;
    @Resource(name="organizationService")
    private OrganizationService<Organization,Long> organizationService;//
    
    @Resource(name="operatorUserService")
    private OperatorUserService<OperatorUser,Long> operatorUserService;//操作員服務對象
    //機構
    private Organization organization;
    
    /**
     * 授權碼驗證
     * @return
     * @throws Exception
     */
    public String passWordVerify() throws Exception{
        try{
            log.debug("*****************進入密碼驗證*******************");
            
            String password = getRequest().getParameter("password");
//            String type = getRequest().getParameter("type");
            
            if(null == password||"".equals(password)){
                sendAjaxResponse("傳遞參數錯誤!!");
                return null;
            }
            
            if(getSessionUser()==null){
                sendAjaxResponse("noLogin");
                return null;
            }
            
            operatorUser = new OperatorUser();
            operatorUser.setId(getSessionUser().getId());
            operatorUser.setAuthorizepwd(MD5.mD5ofStr(password));
            boolean tag = operatorUserService.checkAuthorizePassword(operatorUser);
            if(tag){//密碼驗證成功
                sendAjaxResponse("1");
            }else{
                sendAjaxResponse("-1");
            }
            log.debug("*****************密碼驗證結束*******************");
            return null;
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 進入后台操作員列表 准備好  將要使用的數據
     * @return
     * @throws Exception
     */
    public String list()throws Exception{
        try{
            
            log.debug("進入后台操作員list: OperatorUser "+(OperatorUser)getSession().getAttribute(SESSION_OPERATORUSER));
            log.debug("進入后台操作員list: checkOperatorUser "+checkOperatorUser());
            initRpo("OperatorUserAction");
            if(null == operatorUser){
                operatorUser = new OperatorUser();
            }else{
                String startDateStr = getRequest().getParameter("startDateStr");
                String endDateStr = getRequest().getParameter("endDateStr");
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                if(StringUtils.isNotBlank(startDateStr)){
                    Date startDate = sdf.parse(startDateStr);
                    operatorUser.setStartDate(startDate);
                }
                if(StringUtils.isNotBlank(endDateStr)){
                    Date endDate = sdf.parse(endDateStr);
                    operatorUser.setEndDate(endDate);
                }
            }
            operatorUser.setDeleted(0);
            //查詢出所有的 關於你所在后台操作員的用戶列表
            if(!GlobalConstant.ROOT_ORGANIZATIONID.equals(getSessionUser().getRpOrganId())){//如果不是管理員身份  查出用戶所屬后台操作員的用戶列表
                //operatorUser.setLayer(getSessionUser().getLayer());
                operatorUser.setOrganizationId(getSessionUser().getRpOrganId());
                //operatorUserList = operatorUserService.searchEntityList(operatorUser);
            }
//            if(null != operatorUser.getOrganizationId()){//添加 層級
//                organization = organizationService.searchEntityById(Organization.class, operatorUser.getOrganizationId());
//                operatorUser.setLayer(organization.getLayer());
//            }
            
            /* 屏蔽自己
            //operatorUser.setId(getSessionUser().getId()); */
            
            PageDown pageDown = new PageDown(getCurrentPage(), 20);    //計算起始和終止的條數
            int categoryCount = (int)operatorUserService.getEntityCount(operatorUser);//計算總條數
            pageDown.setTotalRecordNumber(categoryCount);    //總數存到分頁方法里。
            operatorUser.setStart(pageDown.getStart());
            operatorUser.setStop(pageDown.getStop());
            operatorUserList = operatorUserService.searchEntityList(operatorUser);
            pagerString = pageDown.getScript();
            
            //后台用戶角色
            Role role = new Role();
            role.setLayer(operatorUser.getLayer());
            role.setDeleted(0);
            if(!ADMIN_ROLEID.equals(getSessionUser().getRoleId())){//如果是管理員  就顯示所有角色
                role.setOrganizationId(operatorUser.getOrganizationId());
                //添加登錄后台用戶所屬角色
                roleList = new LinkedList<Role>();
                roleList = roleService.searchEntityList(role);
                Role r = new Role();
                r.setId(getSessionUser().getRoleId());
                r = roleService.searchEntity(r);
                roleList.add(0,r);
            }else{
                //添加登錄后台用戶所屬角色
                roleList = roleService.searchEntityList(role);
            }
            
            log.debug("退出后台操作員list");
            
            if(GlobalConstant.ROOT_ORGANIZATIONID.equals(getSessionUser().getRpOrganId())){//如果不是頂級機構
                return "list";
            }else{
                return "agent_list";
            }
            
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }
    }
    
    /**
     * 刪除單個后台用戶
     * @return
     * @throws Exception
     */
    public String delete(){
        try{
            if(operatorUser.getId().equals(getSessionUser().getId())){
                log.warn("非法操作!您不能刪除當前用戶!");
                sendAjaxResponse("false");
                return null;
            }
            //刪除后台用戶
//            if(ZYZF_ORGANIZATIONID.equals(getSessionUser().getRpOrganId())){
                int flag = operatorUserService.logicDelete(operatorUser);
                if(flag > 0){
                    sendAjaxResponse("true");
                }else{
                    sendAjaxResponse("false");
                }
//            }else{
//                notice = "非法操作!";
//                return "globalGoback";
//            }
        }catch(Exception e){
            e.printStackTrace();
            sendAjaxResponse("error");
        }
        return null;
    }
    
    /**
     * 批量刪除后台用戶
     * @return
     * @throws Exception
     */
    public String batchDelete(){
        try{
            log.debug("批量刪除后台用戶"+ids);
            String[] idArray = ids.split(",");
            for(String id : idArray){
                if(id.equals(getSessionUser().getId())){
                    log.warn("非法操作!您不能刪除當前用戶!");
                    sendAjaxResponse("false");
                    return null;
                }
            }
//            if(ZYZF_ORGANIZATIONID.equals(getSessionUser().getRpOrganId())){
                int flag = operatorUserService.logicDeletes(ids);
                if(flag > 0){
                    sendAjaxResponse("true");
                }else{
                    sendAjaxResponse("false");
                }
//            }else{
//                notice = "非法操作!";
//                return "globalGoback";
//            }
        }catch(Exception e){
            e.printStackTrace();
            sendAjaxResponse("error");
        }
        return null;
    }
    
    /**
     * 跳轉到添加
     * @return
     * @throws Exception
     */
    public String addS() throws Exception{
        try{
            operatorUser = getSessionUser();
            
            //登錄用戶所屬機構
            Organization org = new Organization();
            org.setId(operatorUser.getOrganizationId());
            org = organizationService.searchEntity(org);
            
            Role role = new Role();
            
            List<Role> rList = new ArrayList<Role>();
            if(ADMIN_ROLEID.equals(operatorUser.getRoleId())){//超級管理員
                //登錄用戶所屬機構角色
                role.setOrganizationId(operatorUser.getOrganizationId());
                role.setDeleted(0);
                roleList = roleService.searchEntityList(role);
            }else{
                if(1 == org.getType() && 1 == operatorUser.getType()){//OEM管理員
                    //登錄用戶所屬機構角色
                    role.setOrganizationId(operatorUser.getOrganizationId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //OEM公有角色
                    role = new Role();
                    role.setType(2);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }else if(1 < org.getType() && 1 == operatorUser.getType()){//代理商管理員
                    //登錄用戶所屬機構角色
                    role.setOrganizationId(operatorUser.getOrganizationId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //代理商公有角色
                    role = new Role();
                    role.setType(3);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }else if(0 == operatorUser.getType()){
                    if(GlobalConstant.ROOT_ORGANIZATIONID.equals(operatorUser.getOrganizationId())){//頂層用戶登錄
                        //頂級機構角色
                        role.setOrganizationId(operatorUser.getOrganizationId());
                        role.setIsOperatorRole(0);//不是超級管理員的角色
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                    }else if(1 == org.getType()){//OEM用戶登錄
                        role.setOrganizationId(org.getId());
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                        //特殊指定角色
                        role = new Role();
                        role.setAssignOrgId(org.getId());
                        role.setDeleted(0);
                        rList = roleService.searchEntityList(role);
                        if(null != rList && rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                        //OEM公有角色
                        role = new Role();
                        role.setType(2);
                        role.setDeleted(0);
                        rList = new ArrayList<Role>();
                        rList = roleService.searchEntityList(role);
                        if(null != rList || rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                    }else if(1 < org.getType()){//代理商用戶登錄
                        role.setOrganizationId(org.getId());
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                        //特殊指定角色
                        role = new Role();
                        role.setAssignOrgId(org.getId());
                        role.setDeleted(0);
                        rList = roleService.searchEntityList(role);
                        if(null != rList && rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                        //代理商公有角色
                        role = new Role();
                        role.setType(3);
                        role.setDeleted(0);
                        rList = new ArrayList<Role>();
                        rList = roleService.searchEntityList(role);
                        if(null != rList || rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                    }
                }
            }                
                        
            if(GlobalConstant.ROOT_ORGANIZATIONID.equals(operatorUser.getRpOrganId())){//如果不是頂級機構
                return "add";
            }else{
                return "agent_add";
            }
            /*
            if(WANJX_ORGANIZATIONID.equals(user.getRpOrganId())){//所屬帳號
                Role role = new Role();
//                role.setLayer(user.getLayer());
                role.setDeleted(0);
                roleList = roleService.searchEntityList(role);
                return "add";
            }else{//代理商帳號跳轉到添加經銷商管理員界面 -- 棄用
//                Organization param = new Organization();
//                param.setParentId(user.getRpOrganId());
//                organizationList = organizationService.searchOrganizationNameList(param);
//                return "addDealer";
                notice = "非法操作!";
                return "globalGoback";
            }*/
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }
    }
    
    /**
     * 添加或修改用戶時,根據選擇的角色查詢角色機構 
     * @return
     * @throws Exception
     */
    public String searchRoleRpOrganIDAndName()throws Exception{
        try{
            String roleId = getRequest().getParameter("roleId");
            if(StringUtils.isBlank(roleId)){
                notice = "非法操作!";
                return "globalGoback";
            }
            Role role = new Role();
            role.setId(Long.parseLong(roleId));
            role = roleService.searchEntity(role);
            Map<String,Object> element = new LinkedHashMap<String,Object>();
            element.put("rpOrganName", role.getOrganizationName());
            element.put("rpOrganId", role.getOrganizationId());
            sendAjaxResponse(element);
            return null;
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }
    }
    
    /**
     * 添加經銷商管理員
     * @return
     * @throws Exception
     */
//    public String addDealer() throws Exception{
//        try{
//            log.debug("************* 添加經銷商管理員操作開始 ******************");
//            //判斷是否為其所屬經銷商機構
//            Organization params = new Organization();
//            params.setId(operatorUser.getRpOrganId());
//            params.setParentId(getSessionUser().getRpOrganId());
//            params = organizationService.searchEntity(params);
//            if(null == params){
//                notice = "非法操作!";
//                return "globalGoback";
//            }
//            //所屬代理商、角色
//            operatorUser.setOrganizationId(getSessionUser().getOrganizationId());
//            operatorUser.setRoleId(GlobalConstant.DEALER_ROLEID);//添加
//            long id = operatorUserService.insertEntity(operatorUser);
//            if(id > 0){//添加成功返回列表
//                return "listAction";
//            }else{//添加失敗  返回登錄頁
//                notice = "添加失敗!";
//                return "globalGoback";
//            }
//        }catch(Exception e){
//            e.printStackTrace();
//            throw e;
//        }finally{
//            log.debug("************* 添加經銷商管理員操作結束 ******************");
//        }
//    }
    
    /**
     * 添加后台操作員
     * @return
     * @throws Exception
     */
    public String add() throws Exception{
        try{
            //不能添加超級管理員
            if(ADMIN_ROLEID.equals(operatorUser.getRoleId())){
                notice = "非法操作!";
                return "globalGoback";
            }
            if(null == operatorUser.getRpOrganId()){
                notice = "非法操作!權限機構不能為空!";
                return "globalGoback";
            }
            
            
            //--- 暫時所屬機構與權限機構一致 均為 ---
            operatorUser.setOrganizationId(operatorUser.getRpOrganId());
            operatorUser.setType(0);//普通用戶
            
            operatorUser.setPassword(MD5.mD5ofStr(operatorUser.getLoginName()+operatorUser.getPassword()));
            operatorUser.setAuthorizepwd(MD5.mD5ofStr(operatorUser.getAuthorizepwd()));
            //添加
            long id = operatorUserService.insertEntity(operatorUser);
            if(id > 0){//添加成功返回列表
                return "listAction";
            }else{//添加失敗  返回登錄頁
                return "globalLogin";
            }
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }
    }
    
    /**
     * 跳轉到添加代理商管理員頁面
     * @return
     * @throws Exception
     */
    public String addRootS() throws Exception{
        try{
            operatorUser = getSessionUser();
            /*if(!ADMIN_ROLEID.equals(operatorUser.getRoleId()) && !WANJX_ORGANIZATIONID.equals(operatorUser.getRpOrganId())){//不是管理員
                notice = "非法操作!";
                return "globalGoback";
            }
            if(WANJX_ORGANIZATIONID.equals(organization.getId())){
                notice = "非法操作!";
                return "globalGoback";
            }*/
            //代理商驗證
//            Organization params = new Organization();
//            params.setId(organization.getId());
//            params = organizationService.searchEntity(params);
            if(1L == organization.getId()){
                notice = "非法操作,頂級機構不能添加管理員!";
                return "globalGoback";
            }
            Organization params = new Organization();
            params.setId(organization.getId());
            organization = organizationService.searchEntity(params);
            //查詢 當前機構管理員是否存在   限制一個用戶只能添加一個管理員
            OperatorUser paramUser = operatorUserService.searchOperatorUserByRoot(organization.getId());
            if(null != paramUser){//
                notice = "非法操作!該機構已經存在一個管理員了!";
                return "globalGoback";
            }
            return "addRootS";
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }
    }
    
    public String addRoot() throws Exception{
        try{
            //要添加超級管理員 或者 要添加管理員
            /*if(ADMIN_ROLEID.equals(operatorUser.getRoleId()) || WANJX_ORGANIZATIONID.equals(operatorUser.getOrganizationId())){
                notice = "非法操作!";
                return "globalGoback";
            }*/
            if(null == operatorUser.getOrganizationId()){
                notice = "非法操作!權限機構不能為空!";
                return "globalGoback";
            }
            
            
            //設置權限機構
            operatorUser.setRpOrganId(operatorUser.getOrganizationId());
            //設置此機構管理員角色  判斷代理商或經銷商
            Organization params = new Organization();
            params.setId(operatorUser.getOrganizationId());
            params = organizationService.searchEntity(params);
            
            operatorUser.setPassword(MD5.mD5ofStr(operatorUser.getLoginName()+operatorUser.getPassword()));
            operatorUser.setAuthorizepwd(MD5.mD5ofStr(operatorUser.getAuthorizepwd()));
            if(1 == params.getType().intValue()){//OEM
                operatorUser.setRoleId(GlobalConstant.OEM_ROLEID);
            }else if(2 == params.getType().intValue()){//省代
                operatorUser.setRoleId(GlobalConstant.AGENT_ROLEID);//暫時沒有定義
            }else if(3 == params.getType().intValue()){//市代
                operatorUser.setRoleId(GlobalConstant.AGENT_ROLEID);//暫時沒有定義
            }else{//其他代理
                operatorUser.setRoleId(GlobalConstant.AGENT_ROLEID);
            }
            operatorUser.setType(1);
            operatorUserService.insertEntity(operatorUser);
            
            //直接返回到  機構樹形頁面
            return "organizationList";
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }
    }
    
    /**
     * 修改時 查詢后台操作員
     * @return
     * @throws Exception
     */
    public String modifyS() throws Exception{
        try{
            log.debug("**************** 進入修改后台用戶界面 ***********************");
            if(null!= operatorUser.getOrganizationId() && 1L == operatorUser.getOrganizationId()){//屏蔽最上級 多用戶
                notice = "非法操作,頂級機構不能編輯管理員!";
                return "globalGoback";
            }
            
            operatorUser = operatorUserService.searchEntity(operatorUser);
            if(null == operatorUser){
                notice = "非法操作,該機構暫時沒有管理員不能編輯!";
                return "globalGoback";
            }
            
            if(ADMIN_ROLEID.equals(operatorUser.getRoleId())){
                notice = "非法操作,超級管理員不能修改!";
                return "globalGoback";
            }
            
            //被修改用戶所屬機構
            Organization org = new Organization();
            org.setId(operatorUser.getOrganizationId());
            org = organizationService.searchEntity(org);
            
            Role role = new Role();
            
            List<Role> rList = new ArrayList<Role>();
            if(ADMIN_ROLEID.equals(getSessionUser().getRoleId())){//超級管理員
                if(GlobalConstant.ROOT_ORGANIZATIONID.equals(org.getId())){//頂級機構
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                }else if(1 == org.getType()){//OEM
                    //機構所屬角色
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //OEM公有角色
                    role = new Role();
                    role.setType(2);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }else if(1 < org.getType()){//代理商
                    //機構所屬角色
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //代理商公有角色
                    role = new Role();
                    role.setType(3);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }
            }else{
                if(1 == org.getType() && 1 == getSessionUser().getType()){//OEM管理員
                    //登錄用戶所屬機構角色
                    role.setOrganizationId(getSessionUser().getOrganizationId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //OEM公有角色
                    role = new Role();
                    role.setType(2);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }else if(1 < org.getType() && 1 == getSessionUser().getType()){//代理商管理員
                    //登錄用戶所屬機構角色
                    role.setOrganizationId(getSessionUser().getOrganizationId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //代理商公有角色
                    role = new Role();
                    role.setType(3);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }else if(0 == getSessionUser().getType()){
                    if(GlobalConstant.ROOT_ORGANIZATIONID.equals(getSessionUser().getOrganizationId())){//頂層用戶登錄
                        //頂級機構角色
                        role.setOrganizationId(getSessionUser().getOrganizationId());
                        role.setIsOperatorRole(0);//不是超級管理員的角色
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                    }else if(1 == org.getType()){//OEM用戶登錄
                        role.setOrganizationId(org.getId());
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                        //特殊指定角色
                        role = new Role();
                        role.setAssignOrgId(org.getId());
                        role.setDeleted(0);
                        rList = roleService.searchEntityList(role);
                        if(null != rList && rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                        //OEM公有角色
                        role = new Role();
                        role.setType(2);
                        role.setDeleted(0);
                        rList = new ArrayList<Role>();
                        rList = roleService.searchEntityList(role);
                        if(null != rList || rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                    }else if(1 < org.getType()){//代理商用戶登錄
                        role.setOrganizationId(org.getId());
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                        //特殊指定角色
                        role = new Role();
                        role.setAssignOrgId(org.getId());
                        role.setDeleted(0);
                        rList = roleService.searchEntityList(role);
                        if(null != rList && rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                        //代理商公有角色
                        role = new Role();
                        role.setType(3);
                        role.setDeleted(0);
                        rList = new ArrayList<Role>();
                        rList = roleService.searchEntityList(role);
                        if(null != rList || rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                    }
                }
            }
            
            return "modify";
//            if(WANJX_ORGANIZATIONID.equals(user.getRpOrganId())){//所屬帳號
//                Role role = new Role();
////                role.setLayer(user.getLayer());
//                role.setDeleted(0);
//                roleList = roleService.searchEntityList(role);
//                return "modify";
//            }else{
////                Organization param = new Organization();
////                param.setParentId(user.getRpOrganId());
////                organizationList = organizationService.searchOrganizationNameList(param);
////                return "modifyDealer";
//                notice = "非法操作!";
//                return "globalGoback";
//            }
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }finally{
            log.debug("**************** 進入修改后台用戶界面完成 ***********************");
        }
    }
    
    /**
     * 修改經銷商管理員
     * @return
     * @throws Exception
     */
//    public String modifyDealer() throws Exception{
//        try{
//            log.debug("************* 修改經銷商管理員操作開始 ******************");
//            //判斷是否為其所屬經銷商機構
//            Organization params = new Organization();
//            params.setId(operatorUser.getRpOrganId());
//            params.setParentId(getSessionUser().getRpOrganId());
//            params = organizationService.searchEntity(params);
//            if(null == params){
//                notice = "非法操作!";
//                return "globalGoback";
//            }
//            //所屬代理商、角色
//            operatorUser.setOrganizationId(getSessionUser().getOrganizationId());
//            operatorUser.setRoleId(GlobalConstant.DEALER_ROLEID);//添加
//            long id = operatorUserService.updateEntity(operatorUser);
//            if(id > 0){//添加成功返回列表
//                return "listAction";
//            }else{//添加失敗  返回登錄頁
//                notice = "修改失敗!";
//                return "globalGoback";
//            }
//        }catch(Exception e){
//            e.printStackTrace();
//            throw e;
//        }finally{
//            log.debug("************* 修改經銷商管理員操作結束 ******************");
//        }
//    }
    
    /**
     * 修改后台操作員
     * @return
     * @throws Exception
     */
    public String modify() throws Exception{
        try{
            if(null == operatorUser.getRpOrganId()){
                notice = "非法操作!權限機構不能為空!";
                return "globalGoback";
            }
            
            //不能修改為超級管理員    非管理員角色不能修改
            if(ADMIN_ROLEID.equals(operatorUser.getRoleId()) ){//|| !ADMIN_ROLEID.equals(getSessionUser().getRoleId())
                notice = "非法操作,超級管理員不能修改!";
                return "globalGoback";
            }
            //查詢角色 所對應的機構ID 
//            Role role = new Role();
//            role.setId(operatorUser.getRoleId());
//            role = roleService.searchEntity(role);
            if(operatorUser.getRoleId() != GlobalConstant.DEALER_ROLEID){
                operatorUser.setOrganizationId(operatorUser.getRpOrganId());
            }
            int flag = 0;
            operatorUser.setPassword(MD5.mD5ofStr(operatorUser.getLoginName()+operatorUser.getPassword()));
//            operatorUser.setAuthorizepwd(MD5.mD5ofStr(operatorUser.getAuthorizepwd()));
            if(ZYZF_ORGANIZATIONID.equals(operatorUser.getRpOrganId())){
                operatorUser.setAuthorizepwd(MD5.mD5ofStr(operatorUser.getAuthorizepwd()));
                flag = operatorUserService.updateEntity(operatorUser);
            }else{
                OperatorUser param = new OperatorUser();
                param.setId(operatorUser.getId());
                param.setPassword(operatorUser.getPassword());
                param.setUserName(operatorUser.getUserName());
                param.setEmail(operatorUser.getEmail());
                param.setRoleId(operatorUser.getRoleId());
                param.setRpOrganId(operatorUser.getRpOrganId());
                param.setOrganizationId(operatorUser.getRpOrganId());
                param.setMerchantId(operatorUser.getMerchantId());
                param.setAuthorizepwd(MD5.mD5ofStr(operatorUser.getAuthorizepwd()));
                flag = operatorUserService.updateEntity(param);
            }
            if(flag > 0){//修改成功 返回列表
                OperatorUser param = new OperatorUser();
                param.setId(operatorUser.getId());
                operatorUser = operatorUserService.searchEntity(param);
                if(null != operatorUser.getType() && 1 == operatorUser.getType().intValue()){
                    //直接返回到  機構樹形頁面
                    return "organizationList";
                }else{
                    return "listAction";
                }
            }else{//修改失敗 返回登錄頁面
                return "globalLogin";
            }
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }
    }
    
    /**
     * 檢測登錄名是否已經存在
     * @throws Exception
     */
    public void checkName() throws Exception{
        try{
            String name = getRequest().getParameter("param");
            log.debug("************ 檢測用戶名: "+name+" 是否存在 ************");
            Map<String,Object> element = new LinkedHashMap<String,Object>();
            OperatorUser params = new OperatorUser();
            params.setLoginName(name);
            params.setDeleted(0);
            int flag = operatorUserService.getEntityCount(params);
            
            //驗證是否包含中文
            String regex = ".*?[\u4E00-\u9FFF]+.*";
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(name);
            
            //驗證是否包含特殊字符
            String regex1 = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
            Pattern p1 = Pattern.compile(regex1);
            Matcher m1 = p1.matcher(name);
            
            //驗證是否全為數字
            String regex2 = "^[0-9]*$";
            Pattern p2 = Pattern.compile(regex2);
            Matcher m2 = p2.matcher(name);
            
            if(flag > 0){
                element.put("info", "用戶名已存在!");
                element.put("status", "n");
                log.debug("************ 用戶名: "+name+" 已存在 ************");
            }else if(m.matches()){
                element.put("info", "用戶名不能包含中文!");
                element.put("status", "n");
                log.debug("************ 用戶名: "+name+" 包含中文 ************");
            }else if(m1.find()){
                element.put("info", "用戶名不能包含特殊字符!");
                element.put("status", "n");
                log.debug("************ 用戶名: "+name+" 包含特殊字符 ************");
            }else if(m2.matches()){
                element.put("info", "用戶名不能全為數字!");
                element.put("status", "n");
                log.debug("************ 用戶名: "+name+" 全為數字 ************");
            }else{
                element.put("info", "用戶名可以使用!");
                element.put("status", "y");
                log.debug("************ 用戶名: "+name+" 可以使用 ************");
            }
            sendAjaxResponse(element);
        }catch(Exception e){
            e.printStackTrace();
            throw  e;
        }
    }
    
    /**
     * 檢測舊密碼是否正確
     * @throws Exception
     */
    public void checkPassword() throws Exception{
        try{
            log.debug("************ 檢測舊密碼開始 ************");
            String old=getRequest().getParameter("param");
            operatorUser = getSessionUser();
            String pass = MD5.mD5ofStr(operatorUser.getLoginName()+old);
            Map<String,Object> element = new LinkedHashMap<String,Object>();
            if(pass.equals(getSessionUser().getPassword())){
                element.put("info", "");
                element.put("status", "y");
                log.debug("************ 舊密碼正確! ************");
            }else{
                element.put("info", "舊密碼輸入錯誤!");
                element.put("status", "n");
                log.debug("************ 舊密碼錯誤! ************");
            }
            sendAjaxResponse(element);
        }catch(Exception e){
            e.printStackTrace();
            throw  e;
        }finally{
            log.debug("************ 檢測舊密碼結束 ************");
        }
    }
    
    /**
     * 檢測新密碼格式是否符合要求
     * @throws Exception
     */
    public void checkNewPassword() throws Exception{
        try{
            log.debug("************ 檢測新密碼格式是否符合要求開始 ************");
            String newPass = getRequest().getParameter("param");
            
            String regex = "(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{6,}";//必須包含字母和數字 
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(newPass);
               
            Map<String,Object> element = new LinkedHashMap<String,Object>();
            if(m.matches()){
                element.put("info", "");
                element.put("status", "y");
                log.debug("************ 新密碼格式符合要求! ************");
            }else{
                element.put("info", "密碼必須包含字母和數字,請重新輸入!");
                element.put("status", "n");
                log.debug("************ 新密碼格式不符合要求! ************");
            }
            sendAjaxResponse(element);
        }catch(Exception e){
            e.printStackTrace();
            throw  e;
        }finally{
            log.debug("************ 檢測新密碼格式是否符合要求結束 ************");
        }
    }
    
    /**
     * 檢測原授權碼是否正確
     * @throws Exception
     */
    public void checkAuthorizepwd() throws Exception{
        try{
            log.debug("************ 檢測原授權碼開始 ************");
            String oldAuthorizepwd=getRequest().getParameter("param");
            String authorizepwd = MD5.mD5ofStr(oldAuthorizepwd);
            Map<String,Object> element = new LinkedHashMap<String,Object>();
            String auhol=getSessionUser().getAuthorizepwd();
            if(authorizepwd.equals(auhol)){
                element.put("info", "");
                element.put("status", "y");
                log.debug("************ 原授權碼正確! ************");
            }else{
                element.put("info", "原授權碼輸入錯誤!");
                element.put("status", "n");
                log.debug("************ 原授權碼錯誤! ************");
            }
            sendAjaxResponse(element);
        }catch(Exception e){
            e.printStackTrace();
            throw  e;
        }finally{
            log.debug("************ 檢測原授權碼結束 ************");
        }
    }
    
    /**
     * 跳轉至個人設置視圖
     * @return
     * @throws Exception
     */
    public String prePersonalSettings() throws Exception{
        try{
            log.debug("************** 進入個人設置頁面開始 ********************");
            operatorUser = getSessionUser();
            return "settings";
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }finally{
            log.debug("************** 進入個人設置頁面完成 ********************");
        }
    }
    
    /**
     * 個人設置
     * @return
     * @throws Exception
     */
    public String personalSettings() throws Exception{
        try{
            log.debug("************** 個人設置修改操作開始 ********************");
            OperatorUser operaUserSession = getSessionUser();
            String oldPass = MD5.mD5ofStr(operaUserSession.getLoginName()+getRequest().getParameter("oldPass"));
            String password = MD5.mD5ofStr(operaUserSession.getLoginName()+operatorUser.getPassword());
            if(oldPass.equals(getSessionUser().getPassword())){
                OperatorUser user = new OperatorUser();
                user.setId(getSessionUser().getId());
                user.setRoleId(getSessionUser().getRoleId());
                user.setOrganizationId(getSessionUser().getOrganizationId());
                user.setLoginName(getSessionUser().getLoginName());
                user.setRpOrganId(getSessionUser().getRpOrganId());
                //個人設置里要更新的字段
                user.setPassword(password);
                user.setAuthorizepwd(MD5.mD5ofStr(operatorUser.getAuthorizepwd()));
                user.setUserName(operatorUser.getUserName());
                user.setEmail(operatorUser.getEmail());
                int flag = operatorUserService.updateEntity(user);
                if(0 < flag){
                    log.debug("******************* 個人設置修改成功 ********************");
                    //修改SESSION里保存的信息
                    getSessionUser().setPassword(password);
                    getSessionUser().setUserName(user.getUserName());
                    getSessionUser().setEmail(user.getEmail());
                    return "settingsAction";
                }else{
                    log.debug("******************* 個人設置修改失敗 ********************");
                    notice = "修改失敗!";
                    return "globalGoback";
                }
            }else{
                log.debug("******************* 舊密碼輸入錯誤,個人設置修改失敗 ********************");
                notice = "舊密碼輸入錯誤!!!";
                return "globalGoback";
            }
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }finally{
            log.debug("************** 個人設置修改操作完成 ********************");
        }
    }
    
    /**
     * 將所有用戶的密碼  md5 加密
     * @throws Exception
     */
    public String modifyAllUserPaswd()throws Exception{
        try{
            log.debug("************** 將所有用戶的密碼  md5 加密 ********************");
            operatorUser = new OperatorUser();
            operatorUserList = operatorUserService.searchEntityList(operatorUser);
            OperatorUser param = new OperatorUser();
            for(OperatorUser user : operatorUserList){
                param.setId(user.getId());
                param.setPassword(MD5.mD5ofStr(user.getLoginName()+user.getPassword()));
                operatorUserService.updateEntity(param);
            }
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }finally{
            log.debug("************** 將所有用戶的密碼  md5 加密 ********************");
        }
        return null;
    }
    
    public String searchRoleList() throws Exception{
        try {
            List<Role> roleList = new LinkedList<Role>();
            List<Role> rList = new ArrayList<Role>();
            Role role = new Role();
            String rpOrganId = getRequest().getParameter("rpOrganId");
            if(StringUtils.isBlank(rpOrganId)){
                notice = "非法操作!";
                return "globalGoback";
            }
            //登錄用戶所屬機構
            Organization organ = new Organization();
            organ.setId(getSessionUser().getOrganizationId());
            organ = organizationService.searchEntity(organ);
            //權限機構
            Organization org = new Organization();
            org.setId(Long.parseLong(rpOrganId));
            org = organizationService.searchEntity(org);
            
            if(ADMIN_ROLEID.equals(getSessionUser().getRoleId())){//超級管理員登錄
                if(GlobalConstant.ROOT_ORGANIZATIONID.equals(org.getId())){//頂級機構
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                }else if(1 == org.getType()){//OEM
                    //機構所屬角色
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //OEM公有角色
                    role = new Role();
                    role.setType(2);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }else if(1 < org.getType()){//代理商
                    //機構所屬角色
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //代理商公有角色
                    role = new Role();
                    role.setType(3);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }
            }else{
                if(1 == getSessionUser().getType() && 1 == organ.getType()){//OEM管理員登錄
                    if(1 == org.getType()){//權限機構 OEM
                        //機構所屬角色
                        role.setOrganizationId(org.getId());
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                        //特殊指定角色
                        role = new Role();
                        role.setAssignOrgId(org.getId());
                        role.setDeleted(0);
                        rList = roleService.searchEntityList(role);
                        if(null != rList && rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                        //OEM公有角色
                        role = new Role();
                        role.setType(2);
                        role.setDeleted(0);
                        rList = new ArrayList<Role>();
                        rList = roleService.searchEntityList(role);
                        if(null != rList || rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                    }else if(1 < org.getType()){//代理商
                        //機構所屬角色
                        role.setOrganizationId(org.getId());
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                        //特殊指定角色
                        role = new Role();
                        role.setAssignOrgId(org.getId());
                        role.setDeleted(0);
                        rList = roleService.searchEntityList(role);
                        if(null != rList && rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                        //代理商公有角色
                        role = new Role();
                        role.setType(3);
                        role.setDeleted(0);
                        rList = new ArrayList<Role>();
                        rList = roleService.searchEntityList(role);
                        if(null != rList || rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                    }
                    
                }else if(1 == getSessionUser().getType() && 1 < organ.getType()){//代理商管理員
                    //機構所屬角色
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //代理商公有角色
                    role = new Role();
                    role.setType(3);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }else if(0 == getSessionUser().getType()){//普通用戶
                    if(GlobalConstant.ROOT_ORGANIZATIONID.equals(getSessionUser().getOrganizationId())){//頂級機構用戶登錄
                        if(GlobalConstant.ROOT_ORGANIZATIONID.equals(org.getId())){//權限機構  頂級機構
                            //頂級機構角色
                            role.setOrganizationId(getSessionUser().getOrganizationId());
                            role.setIsOperatorRole(0);//不是超級管理員的角色
                            role.setDeleted(0);
                            roleList = roleService.searchEntityList(role);
                        }else if(1 == org.getType()){//權限機構 OEM
                            role.setOrganizationId(org.getId());
                            role.setDeleted(0);
                            roleList = roleService.searchEntityList(role);
                            //特殊指定角色
                            role = new Role();
                            role.setAssignOrgId(org.getId());
                            role.setDeleted(0);
                            rList = roleService.searchEntityList(role);
                            if(null != rList && rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                            //OEM公有角色
                            role = new Role();
                            role.setType(2);
                            role.setDeleted(0);
                            rList = new ArrayList<Role>();
                            rList = roleService.searchEntityList(role);
                            if(null != rList || rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                        }else if(1 < org.getType()){//權限機構 代理商
                            role.setOrganizationId(org.getId());
                            role.setDeleted(0);
                            roleList = roleService.searchEntityList(role);
                            //特殊指定角色
                            role = new Role();
                            role.setAssignOrgId(org.getId());
                            role.setDeleted(0);
                            rList = roleService.searchEntityList(role);
                            if(null != rList && rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                            //代理商公有角色
                            role = new Role();
                            role.setType(3);
                            role.setDeleted(0);
                            rList = new ArrayList<Role>();
                            rList = roleService.searchEntityList(role);
                            if(null != rList || rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                        }
                    }else if(1 == organ.getType()){//OEM普通用戶登錄
                        if(1 == org.getType()){//權限機構 OEM
                            role.setOrganizationId(org.getId());
                            role.setDeleted(0);
                            roleList = roleService.searchEntityList(role);
                            //特殊指定角色
                            role = new Role();
                            role.setAssignOrgId(org.getId());
                            role.setDeleted(0);
                            rList = roleService.searchEntityList(role);
                            if(null != rList && rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                            //OEM公有角色
                            role = new Role();
                            role.setType(2);
                            role.setDeleted(0);
                            rList = new ArrayList<Role>();
                            rList = roleService.searchEntityList(role);
                            if(null != rList || rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                        }else if(1 < org.getType()){//權限機構 代理商
                            role.setOrganizationId(org.getId());
                            role.setDeleted(0);
                            roleList = roleService.searchEntityList(role);
                            //特殊指定角色
                            role = new Role();
                            role.setAssignOrgId(org.getId());
                            role.setDeleted(0);
                            rList = roleService.searchEntityList(role);
                            if(null != rList && rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                            //代理商公有角色
                            role = new Role();
                            role.setType(3);
                            role.setDeleted(0);
                            rList = new ArrayList<Role>();
                            rList = roleService.searchEntityList(role);
                            if(null != rList || rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                        }
                    }else if(1 < organ.getType()){//代理商普通用戶登錄
                        role.setOrganizationId(org.getId());
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                        //特殊指定角色
                        role = new Role();
                        role.setAssignOrgId(org.getId());
                        role.setDeleted(0);
                        rList = roleService.searchEntityList(role);
                        if(null != rList && rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                        //代理商公有角色
                        role = new Role();
                        role.setType(3);
                        role.setDeleted(0);
                        rList = new ArrayList<Role>();
                        rList = roleService.searchEntityList(role);
                        if(null != rList || rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                    }
                }
            }
            
            StringBuilder sb = new StringBuilder("");
                
            for(Role r : roleList){
                sb.append(r.getId()).append(",").append(r.getName()).append("<-->");
            }
            
            this.sendAjaxResponse(sb.toString());
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    
    public String searchRoleByOrgId() throws Exception{
        try{
            log.debug("***********************進入添加合作銀行前 查詢數據**********************");
            List<Role> roleList = new LinkedList<Role>();
            List<Role> rList = new ArrayList<Role>();
            Role role = new Role();
            String rpOrganId = getRequest().getParameter("rpOrganId");
            if(StringUtils.isBlank(rpOrganId)){
                notice = "非法操作!";
                return "globalGoback";
            }
            //登錄用戶所屬機構
            Organization organ = new Organization();
            organ.setId(getSessionUser().getOrganizationId());
            organ = organizationService.searchEntity(organ);
            //權限機構
            Organization org = new Organization();
            org.setId(Long.parseLong(rpOrganId));
            org = organizationService.searchEntity(org);
            
            if(ADMIN_ROLEID.equals(getSessionUser().getRoleId())){//超級管理員登錄
                if(GlobalConstant.ROOT_ORGANIZATIONID.equals(org.getId())){//頂級機構
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                }else if(1 == org.getType()){//OEM
                    //機構所屬角色
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //OEM公有角色
                    role = new Role();
                    role.setType(2);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }else if(1 < org.getType()){//代理商
                    //機構所屬角色
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //代理商公有角色
                    role = new Role();
                    role.setType(3);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }
            }else{
                if(1 == getSessionUser().getType() && 1 == organ.getType()){//OEM管理員登錄
                    if(1 == org.getType()){//權限機構 OEM
                        //機構所屬角色
                        role.setOrganizationId(org.getId());
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                        //特殊指定角色
                        role = new Role();
                        role.setAssignOrgId(org.getId());
                        role.setDeleted(0);
                        rList = roleService.searchEntityList(role);
                        if(null != rList && rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                        //OEM公有角色
                        role = new Role();
                        role.setType(2);
                        role.setDeleted(0);
                        rList = new ArrayList<Role>();
                        rList = roleService.searchEntityList(role);
                        if(null != rList || rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                    }else if(1 < org.getType()){//代理商
                        //機構所屬角色
                        role.setOrganizationId(org.getId());
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                        //特殊指定角色
                        role = new Role();
                        role.setAssignOrgId(org.getId());
                        role.setDeleted(0);
                        rList = roleService.searchEntityList(role);
                        if(null != rList && rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                        //代理商公有角色
                        role = new Role();
                        role.setType(3);
                        role.setDeleted(0);
                        rList = new ArrayList<Role>();
                        rList = roleService.searchEntityList(role);
                        if(null != rList || rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                    }
                    
                }else if(1 == getSessionUser().getType() && 1 < organ.getType()){//代理商管理員
                    //機構所屬角色
                    role.setOrganizationId(org.getId());
                    role.setDeleted(0);
                    roleList = roleService.searchEntityList(role);
                    //特殊指定角色
                    role = new Role();
                    role.setAssignOrgId(org.getId());
                    role.setDeleted(0);
                    rList = roleService.searchEntityList(role);
                    if(null != rList && rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                    //代理商公有角色
                    role = new Role();
                    role.setType(3);
                    role.setDeleted(0);
                    rList = new ArrayList<Role>();
                    rList = roleService.searchEntityList(role);
                    if(null != rList || rList.size() > 0){
                        roleList.addAll(0, rList);
                    }
                }else if(0 == getSessionUser().getType()){//普通用戶
                    if(GlobalConstant.ROOT_ORGANIZATIONID.equals(getSessionUser().getOrganizationId())){//頂級機構用戶登錄
                        if(GlobalConstant.ROOT_ORGANIZATIONID.equals(org.getId())){//權限機構  頂級機構
                            //頂級機構角色
                            role.setOrganizationId(getSessionUser().getOrganizationId());
                            role.setIsOperatorRole(0);//不是超級管理員的角色
                            role.setDeleted(0);
                            roleList = roleService.searchEntityList(role);
                        }else if(1 == org.getType()){//權限機構 OEM
                            role.setOrganizationId(org.getId());
                            role.setDeleted(0);
                            roleList = roleService.searchEntityList(role);
                            //特殊指定角色
                            role = new Role();
                            role.setAssignOrgId(org.getId());
                            role.setDeleted(0);
                            rList = roleService.searchEntityList(role);
                            if(null != rList && rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                            //OEM公有角色
                            role = new Role();
                            role.setType(2);
                            role.setDeleted(0);
                            rList = new ArrayList<Role>();
                            rList = roleService.searchEntityList(role);
                            if(null != rList || rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                        }else if(1 < org.getType()){//權限機構 代理商
                            role.setOrganizationId(org.getId());
                            role.setDeleted(0);
                            roleList = roleService.searchEntityList(role);
                            //特殊指定角色
                            role = new Role();
                            role.setAssignOrgId(org.getId());
                            role.setDeleted(0);
                            rList = roleService.searchEntityList(role);
                            if(null != rList && rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                            //代理商公有角色
                            role = new Role();
                            role.setType(3);
                            role.setDeleted(0);
                            rList = new ArrayList<Role>();
                            rList = roleService.searchEntityList(role);
                            if(null != rList || rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                        }
                    }else if(1 == organ.getType()){//OEM普通用戶登錄
                        if(1 == org.getType()){//權限機構 OEM
                            role.setOrganizationId(org.getId());
                            role.setDeleted(0);
                            roleList = roleService.searchEntityList(role);
                            //特殊指定角色
                            role = new Role();
                            role.setAssignOrgId(org.getId());
                            role.setDeleted(0);
                            rList = roleService.searchEntityList(role);
                            if(null != rList && rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                            //OEM公有角色
                            role = new Role();
                            role.setType(2);
                            role.setDeleted(0);
                            rList = new ArrayList<Role>();
                            rList = roleService.searchEntityList(role);
                            if(null != rList || rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                        }else if(1 < org.getType()){//權限機構 代理商
                            role.setOrganizationId(org.getId());
                            role.setDeleted(0);
                            roleList = roleService.searchEntityList(role);
                            //特殊指定角色
                            role = new Role();
                            role.setAssignOrgId(org.getId());
                            role.setDeleted(0);
                            rList = roleService.searchEntityList(role);
                            if(null != rList && rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                            //代理商公有角色
                            role = new Role();
                            role.setType(3);
                            role.setDeleted(0);
                            rList = new ArrayList<Role>();
                            rList = roleService.searchEntityList(role);
                            if(null != rList || rList.size() > 0){
                                roleList.addAll(0, rList);
                            }
                        }
                    }else if(1 < organ.getType()){//代理商普通用戶登錄
                        role.setOrganizationId(org.getId());
                        role.setDeleted(0);
                        roleList = roleService.searchEntityList(role);
                        //特殊指定角色
                        role = new Role();
                        role.setAssignOrgId(org.getId());
                        role.setDeleted(0);
                        rList = roleService.searchEntityList(role);
                        if(null != rList && rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                        //代理商公有角色
                        role = new Role();
                        role.setType(3);
                        role.setDeleted(0);
                        rList = new ArrayList<Role>();
                        rList = roleService.searchEntityList(role);
                        if(null != rList || rList.size() > 0){
                            roleList.addAll(0, rList);
                        }
                    }
                }
            }
            
            StringBuilder sb = new StringBuilder("");
            
            for(Role r : roleList){
                sb.append(r.getId()).append(",").append(r.getName()).append("<-->");
            }
            
            this.sendAjaxResponse(sb.toString());
            return null;
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }
    
    }
    
    //---------------------set get start
    public OperatorUser getOperatorUser() {
        return operatorUser;
    }
    public void setOperatorUser(OperatorUser operatorUser) {
        this.operatorUser = operatorUser;
    }
    
    public List<OperatorUser> getOperatorUserList() {
        return operatorUserList;
    }
    public void setOperatorUserList(List<OperatorUser> operatorUserList) {
        this.operatorUserList = operatorUserList;
    }

    public List<Role> getRoleList() {
        return roleList;
    }
    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }

    public List<Organization> getOrganizationList() {
        return organizationList;
    }
    public void setOrganizationList(List<Organization> organizationList) {
        this.organizationList = organizationList;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }
    //---------------------set get end

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM