pageMultiAjax.jsp 8.53 KB
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="weaver.general.*"%>
<%@ page import="weaver.hrm.*"%>
<%@ page import="java.util.*,java.lang.*"%>
<%@ page import="weaver.systeminfo.*"%>
<%@ page import="net.sf.json.JSONArray"%>
<%@ page import="net.sf.json.JSONObject"%>

<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="hpu" class="weaver.page.PageUtil" scope="page"/>
	
	<% 
	User user = HrmUserVarify.getUser(request, response);
	String src = Util.null2String(request.getParameter("src"));
	String ids = Util.null2String(request.getParameter("ids"));
	String type = Util.null2String(request.getParameter("type"));
	boolean isDetachable=hpu.isDetachable(request);
	if (ids.trim().startsWith(",")) {
		ids = ids.substring(1);
	}
	String infoname = Util.null2String(request.getParameter("name"));
	//out.println("infoname--"+infoname);
	String infodesc = Util.null2String(request.getParameter("desc"));
	int subCompanyId = user.getUserSubCompany1();
	ArrayList idList = new ArrayList();
	ArrayList nameList = new ArrayList();
	ArrayList descList = new ArrayList();
	String imagefilename = "/images/hdMaintenance_wev8.gif";
	String titlename = "";
	String 	sqlWhere="";
	String sql = "select id,infoname,infodesc from hpinfo ";
	JSONArray jsonArr = new JSONArray();
	JSONObject json = new JSONObject();
	if (src.equalsIgnoreCase("dest")) {
		if ("aft".equals(type)){
			if ("sqlserver".equals(rs.getDBType())){
				if (user.getUID()==1){  //sysadmin
					sqlWhere = " where  (creatortype=4  or creatortype=3 and creatorid="+subCompanyId+"  ) and subcompanyid!=-1 and  infoname != ''";
				} else {
					sqlWhere = " where   (creatortype=3 and creatorid="+subCompanyId+") and subcompanyid!=-1 and  infoname != ''";
				}
			} else {
				if (user.getUID()==1){  //sysadmin
					sqlWhere = " where  (creatortype=4  or creatortype=3 and creatorid="+subCompanyId+"  ) and subcompanyid!=-1 and  infoname is not null";
				} else {
					sqlWhere = " where   (creatortype=3 and creatorid="+subCompanyId+"  )  and subcompanyid!=-1 and  infoname is not null";
				}
			}
			//名称过滤
			/* if(!"".equals(infoname) && infoname != null){
				sqlWhere = sqlWhere + " and infoname like '%"+infoname+"%'";
			}
			if(!"".equals(infodesc) && infodesc != null){
				sqlWhere = sqlWhere + " and infodesc like '%"+infodesc+"%'";
			} */
			if("".equals(ids)){
				ids="''";
			}
			sqlWhere += " and id in ("+ids+") ";
			sql +=sqlWhere+" order by id, subcompanyid ";
			rs.execute(sql);
			while (rs.next()){
				String id = Util.null2String(rs.getString("id"));
				String infoname1 = Util.null2String(rs.getString("infoname"));
				String infodesc1 = Util.null2String(rs.getString("infodesc"));
				JSONObject tmp = new JSONObject();
				tmp.put("id", id);
				tmp.put("infoname", infoname1);
				tmp.put("infodesc", infodesc1);
				jsonArr.add(tmp);
			}//-------------------------------------
			String 	sqlWhere2="";
			if ("sqlserver".equals(rs.getDBType())){
				sqlWhere2=" and subcompanyid!=-1 and h1.infoname != ''";
			} else {
				sqlWhere2=" and subcompanyid!=-1 and h1.infoname is not null";
			}	
			/* if(!"".equals(infoname) && infoname != null){
				sqlWhere2 = sqlWhere2 + " and infoname like '%"+infoname+"%'";
			}			
			if(!"".equals(infodesc) && infodesc != null){
				sqlWhere2 = sqlWhere2 + " and infodesc like '%"+infodesc+"%'";
			}		 */	
			sqlWhere2 = sqlWhere2 + " and id in ("+ids+")";			
			if(subCompanyId==0 && user.getUID()==1&&isDetachable||subCompanyId==0&&!isDetachable){
				sql = "select id,infoname,infodesc from hpinfo h1 where 1=1 " + sqlWhere2 + " order by subcompanyid ";
				rs.execute(sql);
				while (rs.next())
				{
					String id = Util.null2String(rs.getString("id"));
					String infoname1 = Util.null2String(rs.getString("infoname"));
					String infodesc1 = Util.null2String(rs.getString("infodesc"));
					JSONObject tmp = new JSONObject();
					tmp.put("id", id);
					tmp.put("infoname", infoname1);
					tmp.put("infodesc", infodesc1);
					jsonArr.add(tmp);
				}
			}
			
		}else if ("pre".equals(type)){
			titlename = SystemEnv.getHtmlLabelName(23017, user.getLanguage())+":"+SystemEnv.getHtmlLabelName(320, user.getLanguage());
			if ("sqlserver".equals(rs.getDBType())){
				sqlWhere = " where creatortype=0 and subcompanyid=-1 and infoname != ''";
			}else{			
				sqlWhere = " where creatortype=0 and subcompanyid=-1 and infoname is not null";
			}
			if("".equals(ids)){
				ids="''";
			}
			sqlWhere += " and id in ("+ids+") ";
			sql +=sqlWhere+" order by id,subcompanyid ";
			rs.execute(sql);
			while (rs.next()){
				String id = Util.null2String(rs.getString("id"));
				String infoname1 = Util.null2String(rs.getString("infoname"));
				String infodesc1 = Util.null2String(rs.getString("infodesc"));
				JSONObject tmp = new JSONObject();
				tmp.put("id", id);
				tmp.put("infoname", infoname1);
				tmp.put("infodesc", infodesc1);
				jsonArr.add(tmp);
			}
		}
		
		json.put("mapList", jsonArr.toString());
		out.println(json.toString());
		return ;
	}
	if ("aft".equals(type)){
		if ("sqlserver".equals(rs.getDBType())){
			if (user.getUID()==1){  //sysadmin
				sqlWhere = " where  (creatortype=4  or creatortype=3 and creatorid="+subCompanyId+"  ) and subcompanyid!=-1 and  infoname != ''";
			} else {
				sqlWhere = " where   (creatortype=3 and creatorid="+subCompanyId+") and subcompanyid!=-1 and  infoname != ''";
			}
		} else {
			if (user.getUID()==1){  //sysadmin
				sqlWhere = " where  (creatortype=4  or creatortype=3 and creatorid="+subCompanyId+"  ) and subcompanyid!=-1 and  infoname is not null";
			} else {
				sqlWhere = " where   (creatortype=3 and creatorid="+subCompanyId+"  )  and subcompanyid!=-1 and  infoname is not null";
			}
		}
		//名称过滤
		if(!"".equals(infoname) && infoname != null){
			sqlWhere = sqlWhere + " and infoname like '%"+infoname+"%'";
		}
		if(!"".equals(infodesc) && infodesc != null){
			sqlWhere = sqlWhere + " and infodesc like '%"+infodesc+"%'";
		}
		sql +=sqlWhere+" order by id,subcompanyid ";
		rs.execute(sql);
		while (rs.next())
		{
			String id = Util.null2String(rs.getString("id"));
			String infoname1 = Util.null2String(rs.getString("infoname"));
			String infodesc1 = Util.null2String(rs.getString("infodesc"));
			JSONObject tmp = new JSONObject();
			tmp.put("id", id);
			tmp.put("infoname", infoname1);
			tmp.put("infodesc", infodesc1);
			jsonArr.add(tmp);
		}
		//-------------------------------------
		String 	sqlWhere2="";
		if ("sqlserver".equals(rs.getDBType())){
			sqlWhere2=" and subcompanyid!=-1 and h1.infoname != ''";
		} else {
			sqlWhere2=" and subcompanyid!=-1 and h1.infoname is not null";
		}
		//名称过滤
		if(!"".equals(infoname) && infoname != null){
			sqlWhere2 = sqlWhere2 + " and infoname like '%"+infoname+"%'";
		}
		if(!"".equals(infodesc) && infodesc != null){
			sqlWhere2 = sqlWhere2 + " and infodesc like '%"+infodesc+"%'";
		}
		// 无功能权限  但有 页面 维护权限
		if(subCompanyId==0 && user.getUID()==1&&isDetachable||subCompanyId==0&&!isDetachable){
			sql = "select id,infoname,infodesc from hpinfo h1 where 1=1 "+ sqlWhere2 + " order by subcompanyid ";
			rs.execute(sql);
			while (rs.next()){
				String id = Util.null2String(rs.getString("id"));
				String infoname1 = Util.null2String(rs.getString("infoname"));
				String infodesc1 = Util.null2String(rs.getString("infodesc"));
				JSONObject tmp = new JSONObject();
				tmp.put("id", id);
				tmp.put("infoname", infoname1);
				tmp.put("infodesc", infodesc1);
				jsonArr.add(tmp);
			}
		}
	}
	else if ("pre".equals(type))
	{
		titlename = SystemEnv.getHtmlLabelName(23017, user.getLanguage())+":"+SystemEnv.getHtmlLabelName(320, user.getLanguage());
		if ("sqlserver".equals(rs.getDBType())){
			sqlWhere = " where creatortype=0 and subcompanyid=-1 and infoname != ''";
		}else{
			sqlWhere = " where creatortype=0 and subcompanyid=-1 and infoname is not null";
		}
		if(!"".equals(infoname) && infoname != null){
			sqlWhere = sqlWhere + " and infoname like '%"+infoname+"%'";
		}
		if(!"".equals(infodesc) && infodesc != null){
			sqlWhere = sqlWhere + " and infodesc like '%"+infodesc+"%'";
		}
		sql +=sqlWhere+" order by id,subcompanyid ";
		rs.execute(sql);
		while (rs.next())
		{
			String id = Util.null2String(rs.getString("id"));
			String infoname1 = Util.null2String(rs.getString("infoname"));
			String infodesc1 = Util.null2String(rs.getString("infodesc"));
			JSONObject tmp = new JSONObject();
			tmp.put("id", id);
			tmp.put("infoname", infoname1);
			tmp.put("infodesc", infodesc1);
			jsonArr.add(tmp);
		}
	}
	
	json.put("mapList", jsonArr.toString());
	out.println(json.toString());
%>