package com.api.doc.search.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.api.doc.detail.util.DocSecretLevelUtil;
import com.engine.hrm.biz.HrmClassifiedProtectionBiz;
import com.api.doc.detail.util.CooperativeUtilForDoc;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.crm.Maint.CustomerInfoComInfo;
import weaver.crm.Maint.CustomerTypeComInfo;
import weaver.docs.category.SecCategoryComInfo;
import weaver.docs.docs.DocViewer;
import weaver.general.BaseBean;
import weaver.general.IsGovProj;
import weaver.general.KnowledgeTransMethod;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.companyvirtual.CompanyVirtualComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.moduledetach.ManageDetachComInfo;
import weaver.hrm.orggroup.HrmOrgGroupComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.hrm.roles.RolesComInfo;
import weaver.splitepage.operate.SpopForDoc;
import weaver.systeminfo.SystemEnv;

import com.api.browser.bean.BrowserBean;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.api.doc.detail.service.DocViewPermission;
import com.api.doc.detail.util.DocCoopereateUtil;
import com.api.doc.search.util.BrowserType;
import com.api.doc.search.util.DocSptm;
import com.api.doc.search.util.DocTableType;
import com.api.doc.search.util.PatternUtil;
import com.cloudstore.dev.api.util.Util_TableMap;
import com.engine.doc.util.WaterMarkUtil;

/**
 * 文档权限
 * @author wangqs
 * */
public class DocShareService {
	
	
	public static String OBJ_TYPE = "objType";    //对象类型
	public static String OBJ_ID = "obj_id";
	public static String SEC_LEVEL = "seclevel";
	public static String DOWNLOAD = "download";
	public static String HAS_SUB = "has_sub";
	public static String FROM_LEVEL = "from_Level";
	public static String TO_LEVEL = "to_Level";
	public static String POST_LEVEL = "post_Level";
	public static String TARGET_OBJECT_ID = "target_object_id";
	public static String ROLE_LEVEL = "role_level";
	public static String CREATER_ORGID = "creater_orgid";
	
	public static final int OBJ_TYPE_CUSTOMER_TYPE = -1; //对象类型-客户类型
	public static final int OBJ_TYPE_USER = 1; //对象类型-人力资源
	public static final int OBJ_TYPE_SUB_COMPANY = 2;//对象类型-分部
	public static final int OBJ_TYPE_DEPARTMENT = 3;//对象类型-部门
	public static final int OBJ_TYPE_ROLE = 4;//对象类型-角色
	public static final int OBJ_TYPE_ALL = 5;//对象类型-所有人
	public static final int OBJ_TYPE_GROUP = 6;//对象类型-群组
	public static final int OBJ_TYPE_CUSTOMER = 9; //对象类型-指定客户
	public static final int OBJ_TYPE_POST = 10;//对象类型-岗位
	public static final int OBJ_TYPE_CREATER_SELF = 80;//对象类型-创建人本人 
	public static final int OBJ_TYPE_CREATER_SELF_2 = -80;//对象类型-创建人本人 
	public static final int OBJ_TYPE_CREATER_MANAGER = 81;//对象类型-创建人直接上级 
	public static final int OBJ_TYPE_CREATER_MANAGER_2 = -81;//对象类型-创建人直接上级 
	public static final int OBJ_TYPE_CREATER_ALL_MANAGER = 82;//对象类型-创建人所有上级 
	public static final int OBJ_TYPE_CREATER_SUB_COMPANY = 84;//对象类型-创建人本分部
	public static final int OBJ_TYPE_CREATER_DEPARTMENT = 85;//对象类型-创建人本部门
	
	public static final int OBJ_TYPE_DEFAULT = OBJ_TYPE_USER;
	
	public static final int SEC_LEVEL_VIEW = 1; //查看
	public static final int SEC_LEVEL_EDIT = 2;//编辑
	public static final int SEC_LEVEL_ALL = 3;//完全控制
	public static final int SEC_LEVEL_DEFAULT = SEC_LEVEL_VIEW;
	
	public static final int ROLE_LEVEL_DEPARTMENT = 0; //部门
	public static final int ROLE_LEVEL_SUB_COMPANY = 1; //分部
	public static final int ROLE_LEVEL_ALL = 2;  //总部
	public static final int ROLE_LEVEL_DEFAULT = ROLE_LEVEL_DEPARTMENT;
	
	public static final int POST_LEVEL_ALL = 1;
	public static final int POST_LEVEL_SUB_COMPANY = 2;
	public static final int POST_LEVEL_DEPARTMENT = 3;
	public static final int POST_LEVEL_DEFAULT = POST_LEVEL_ALL;
	
	public static final int SEC_LEVEL_FROM = 10;  //安全级别 默认起始值
	public static final int SEC_LEVEL_TO = 100;	//安全级别 默认结束值

	private static int  sharelevel=1; // 1.查看，2.编辑，3.完全控制
	
	
	

	/**
	 * 文档权限列表
	 * @params user
	 * @params docid
	 * @params params 自定义参数集
	 * @author wangqs 
	 * */
	public Map<String,Object> getShareList(User user,int docid,Map<String,String> params){
		
		SecCategoryComInfo scci = new SecCategoryComInfo();
		String secId= "";
		RecordSet rs = new RecordSet();
		rs.executeQuery("select seccategory from docdetail where id=" + docid);
		if(rs.next()){
			secId=rs.getString("seccategory");
		}
		boolean nodownload = scci.getNoDownload(secId).equals("1");//得到此分录下的文档最大可上传附件大小

		String col = "";
		
		col += "<col width=\"10%\" labelid=\"18495\"  text=\""+SystemEnv.getHtmlLabelName(18495,user.getLanguage())+"\" column=\"type\"/>";//共享类型
		col += "<col width=\"20%\" labelid=\"21956\"  text=\""+SystemEnv.getHtmlLabelName(21956,user.getLanguage())+"\" column=\"shareName\" />";	//共享对象
		col += "<col width=\"25%\" labelid=\"106\"  text=\""+SystemEnv.getHtmlLabelName(106,user.getLanguage())+"\" column=\"shareRealName\" />"; //对象名称
		col += "<col width=\"20%\" labelid=\"683\"  text=\""+SystemEnv.getHtmlLabelName(683,user.getLanguage())+"\" column=\"shareRealLevel\"/>"; //安全级别
		col += "<col width=\"15%\" labelid=\"385\"  text=\""+SystemEnv.getHtmlLabelName(385,user.getLanguage())+"\" column=\"shareRealType\"/>"; //权限
		if(!nodownload){
			col += "<col width=\"15%\" labelid=\"32070\"  text=\""+SystemEnv.getHtmlLabelName(32070,user.getLanguage())+"\" column=\"downloadlevelName\" />";//下载权限
		}
		
		String sourceparams = "id:"+docid+"";
		if(params != null && "1".equals(params.get("iscooper"))){
			sourceparams += "+iscooper:1";
		}
		
		String tableString =
			   "<table instanceid=\"docShareList\" pageUid=\"" + DocTableType.DOC_SHARE.getPageUid() + "\" pageId=\"" + DocTableType.DOC_SHARE.getPageUid() + "\" datasource=\"com.api.doc.search.service.DocShareService.getDocShare\" sourceparams=\""+sourceparams+"\" " +
			   		"pagesize=\"" + DocTableType.DOC_SHARE.getPageSize() + "\" tabletype=\"checkbox\">" +
			   "<sql backfields=\"*\"  sqlform=\"temp\" sqlorderby=\"shareId\"  sqlprimarykey=\"shareId\" sqlsortway=\"desc\"  />"+
			   " <checkboxpopedom  showmethod=\"com.api.doc.search.util.DocSptm.getShareCheckbox\" id=\"checkbox\"  popedompara=\"column:chk\" />"+
			   "<head>" +
			   	col +
			   "</head>"+
			   "</table>";      
				
		String sessionkey = DocTableType.DOC_SHARE.getPageUid() + "_" + Util.getEncrypt(Util.getRandom());
		Util_TableMap.setVal(sessionkey, tableString);
		
		Map<String,Object> apidatas = new HashMap<String,Object>();
		
		apidatas.put("sessionkey", sessionkey);
	
		return apidatas;
	}
	
	public List<Map<String,String>> getDocShare(User user, Map<String, Object> otherparams, HttpServletRequest request, HttpServletResponse response){
		Integer docid = Integer.parseInt((String) otherparams.get("id"));
        //DocShare docShare = new DocShare();
        ArrayList<Map<String,String>> dataList=new ArrayList<Map<String,String>>();
        
        
        // 分页信息
        int startSize = Util.getIntValue(request.getParameter("min"),0);
        if(startSize <= 0){
        	startSize = Util.getIntValue((String)request.getAttribute("min"),0);
        }
        int pageSize = Util.getIntValue(request.getParameter("pageSize"),0);
        if(pageSize <= 0){
        	pageSize = Util.getIntValue((String)request.getAttribute("pageSize"),0);
        }
        
       // new BaseBean().writeLog("---------------" + pageNum + "=======" + pageSize);
        int endSize = startSize+pageSize;
        
        try{
	        dataList.addAll(getShareList(1,docid,"true",user.getLanguage(),false));
	        dataList.addAll(getShareList(2,docid,"true",user.getLanguage(),false));
	        dataList.addAll(getShareList(3,docid,"true",user.getLanguage(),false));
	        dataList.addAll(getShareList(4,docid,"true",user.getLanguage(),false));
	        
	        startSize = startSize - dataList.size();
	        endSize = endSize - dataList.size();
	        
	        List<Map<String,String>> shareList = getShareList(5,docid,"true",user.getLanguage(),false);
	        
	        String shareEdit = Util.null2String(new BaseBean().getPropValue("doc_cooperate_edit_set","shareEdit"));
	        
	        if("1".equals(otherparams.get("iscooper")+"") && !"0".equals(shareEdit)){
	        
	        	Map<String,String> userMap = new HashMap<String,String>();
	        	
	        	
				String editLabel = SystemEnv.getHtmlLabelName(93,user.getLanguage());

				String downloadlevelName = "";
	        	
				int i = 1;
				
	        	for(Map<String,String> data : shareList){
	        		if(i >= startSize && i < endSize){
	        			
	        			//new BaseBean().writeLog("--------------------" + i);
		        		if("1".equals(data.get("shareType"))){
		        			if(("1".equals(data.get("shareLevel")))){
		        				if(userMap.get(data.get("shareUserId")) == null){
		        					String permissionType = new DocCoopereateUtil().takePermission(new User(Util.getIntValue(data.get("shareUserId"))),docid+"");
		        					if(DocCoopereateUtil.WRITE.equals(permissionType)){
		        	            		data.put("downloadlevelName","");
		        	            		data.put("shareRealType",editLabel);
		        	            		userMap.put(data.get("shareUserId"),"1");
		        	            	}
		        				}else{
		        					data.put("downloadlevelName","");
	        	            		data.put("shareRealType",editLabel);
		        				}
		        			}else{
		        				userMap.put(data.get("shareUserId"),"1");
		        			}
		        		}
	        		}
	        		i++;
	        	}
	        }
	        dataList.addAll(shareList);

        }catch(Exception e){
        }
        return dataList;
    }
	
	/**
	 * 是否有新增、删除按钮
	 * */
	public Map<String,Object> canEdit(User user,int docid){
		Map<String,Object> apidatas = new HashMap<String,Object>();
		String hasBtn = "-1";
		String hasDelBtn = "-1";
		int userid=user.getUID();
		String logintype = user.getLogintype();
		String userSeclevel = user.getSeclevel();
		String userType = ""+user.getType();
		String userdepartment = ""+user.getUserDepartment();
		String usersubcomany = ""+user.getUserSubCompany1();
		String userInfo=logintype+"_"+userid+"_"+userSeclevel+"_"+userType+"_"+userdepartment+"_"+usersubcomany;
		SpopForDoc sfd = new SpopForDoc();
		try{
			ArrayList PdocList = sfd.getDocOpratePopedom(""+docid,userInfo);
			if (((String)PdocList.get(3)).equals("true")){ 
				RecordSet rs = new RecordSet();
				rs.executeQuery("select d2.allownModiMshareL,d2.allownModiMshareW,d2.shareable from docdetail d1,DocSecCategory d2 where d1.seccategory=d2.id and d1.id=" + docid);
				int isAllowModiMShare = 0;
				int isAllowModiNMShare = 0;
				if (rs.next()) {
					isAllowModiMShare = Util.getIntValue(Util.null2String(rs.getString("allownModiMshareL")),0);
					isAllowModiNMShare = Util.getIntValue(Util.null2String(rs.getString("shareable")),0);
				}
				if(isAllowModiNMShare==1){
					hasBtn="1";
					hasDelBtn="1";
				}else if(isAllowModiMShare==1){
					hasDelBtn="1";
				}
				
			}
		}catch(Exception e){
			
		}
		
		apidatas.put("hasAddBtn", hasBtn);
		apidatas.put("hasDelBtn", hasDelBtn);
		return apidatas;
	}
	
	/**
	 * 批量调整共享
	 * */
	public void doBatch(String docids,User user,String defaultshare,String nondefaultshare,String otherversion){
		
		
		RecordSet rs = new RecordSet();
		
		
		String docSql = docids.contains(",") ? (" in (" + docids + ")") : (" = " + docids);
		if("1".equals(otherversion) && false){ // 处理历史版本文件
			rs.executeQuery("select t1.id from DocDetail t1 where exists " +
					"(select 1 from DocDetail t2 where t1.doceditionid=t2.doceditionid and t2.id" + docSql + " and t2.doceditionid>0)");
			String editids = "";
			while(rs.next()){
				String id = rs.getString("id");
				if(("," + docids + ",").indexOf("," + id + ",") == -1){
					docids += "," + id;
					editids += "," + id;
				}
			}
			editids = editids.contains(",") ? editids.substring(1) : editids;
			
			if(!editids.isEmpty()){
				String copyColumn = "sharetype,seclevel,rolelevel,userid,subcompanyid,departmentid,roleid," +
						"foralluser,sharedcrm,crmid,sharesource,isSecDefaultShare,creatordepartmentid,creatorsubcompanyid," +
						"doccreatorid,orggroupid,downloadlevel,allmanagers,includesub,orgid,seclevelmax,joblevel," +
						"jobdepartment,jobsubcompany,jobids";
				rs.executeUpdate("insert into DocShare(docid," + copyColumn + ") " +
						"(select docid," + copyColumn + ")");
			}
		}
		
		String sql = "delete from DocShare where docid " + docSql ;
		
		if("1".equals(defaultshare) && !"1".equals(nondefaultshare)){
			sql += " and isSecDefaultShare='1'";
		}else if(!"1".equals(defaultshare) && "1".equals(nondefaultshare)){
			sql += " and (isSecDefaultShare is null or isSecDefaultShare='' or isSecDefaultShare!='1')";
		}
		rs.executeUpdate(sql);
		
		String ndocids = "";
		for(String docid : docids.split(",")){
			ndocids += ",-" + docid;
		}
		ndocids = ndocids.substring(1);
		
		docSql = ndocids.contains(",") ? (" in (" + ndocids + ")") : (" = " + ndocids);
		sql = "update DocShare set docid=-docid where docid" + docSql;
		rs.executeUpdate(sql);
		
		DocViewer dv = new DocViewer();
		for(String docid : docids.split(",")){
			try{
				dv.setDocShareByDoc(docid);
			}catch(Exception e){
				
			}
		}
		
	}
	
	/**
	 * 删除共享
	 * */
	public Map<String,Object> deleteShare(User user,int docid,String shareids){
		Map<String,Object> apidatas = new HashMap<String,Object>();
		
		shareids = PatternUtil.trimSplit(shareids,",");
		
		if(!PatternUtil.isAllNumber(shareids)){
			apidatas.put("status", -1);
			apidatas.put("api_status", false);
			apidatas.put("msg", SystemEnv.getHtmlLabelName(500537,user.getLanguage()));//数据异常!
			return apidatas;
		}
		
		
		String shareidSQL = shareids.contains(",") ? (" in (" + shareids + ")") : (" = " + shareids);
		
		RecordSet rs = new RecordSet();
		
		DocViewer dv = new DocViewer();
		try{
			rs.execute("delete from DocShare where docid=" + docid + " and id " + shareidSQL);
			dv.setDocShareByDoc(docid + "");
			apidatas.put("status", 1);
			apidatas.put("api_status", true);
		}catch(Exception e){
			apidatas.put("status", -1);
			apidatas.put("api_status", false);
			apidatas.put("msg", SystemEnv.getHtmlLabelName(83473,user.getLanguage()));// 删除失败!
			rs.writeLog(e);
			e.printStackTrace();
		}
		
		return apidatas;
	}
	
	/**
	 * 删除所有共享
	 * @author wangqs
	 * @params docid-文档id，delNow-是否立即删除，syncToDetail-是否同步shareinnerdoc
	 * */
	public void deleteAll(String docid,boolean delNow,boolean syncToDetail){
		RecordSet rs = new RecordSet();
		
		String idStr = docid.contains(",") ? (" in (" + docid + ")") : (" = " + docid);
		
		if(delNow){
			rs.executeUpdate("delete from DocShare where docid" + idStr);
		}else{
			rs.executeUpdate("update DocShare set docid=-docid where docid" + idStr);
		}
		if(syncToDetail){
			try{
				DocViewer dv = new DocViewer();
				for(String id : docid.split(",")){
					dv.setDocShareByDoc(id);
				}
			}catch(Exception e){
			}
		}
	}
	
	/**
	 * 删除非默认共享
	 * @author wangqs
	 * @params docid-文档id，delNow-是否立即删除，syncToDetail-是否同步shareinnerdoc
	 * */
	public void deleteNonDefault(String docid,boolean delNow,boolean syncToDetail){
		RecordSet rs = new RecordSet();
		
		String idStr = docid.contains(",") ? (" in (" + docid + ")") : (" = " + docid);
		
		if(delNow){
			rs.executeUpdate("delete from DocShare where docid" + idStr + " and " +
					"(isSecDefaultShare is null or isSecDefaultShare='' or isSecDefaultShare='0')");
		}else{
			rs.executeUpdate("update DocShare set docid=-docid where docid" + idStr + " and " +
				"(isSecDefaultShare is null or isSecDefaultShare='' or isSecDefaultShare='0')");
		}
		if(syncToDetail){
			try{
				DocViewer dv = new DocViewer();
				for(String id : docid.split(",")){
					dv.setDocShareByDoc(id);
				}
			}catch(Exception e){
			}
		}
	}
	
	/**
	 * 删除默认共享
	 * @author wangqs
	 * @params docid-文档id，delNow-是否立即删除，syncToDetail-是否同步shareinnerdoc
	 * */
	public void deleteDefault(String docid,boolean delNow,boolean syncToDetail){
		
		String idStr = docid.contains(",") ? (" in (" + docid + ")") : (" = " + docid);
		
		RecordSet rs = new RecordSet();
		if(delNow){
			rs.executeUpdate("delete from DocShare where docid" + idStr + " and isSecDefaultShare='1'");
		}else{
			rs.executeUpdate("update DocShare set docid=-docid where docid" + idStr + " and isSecDefaultShare='1'");
		}
		if(syncToDetail){
			try{
				DocViewer dv = new DocViewer();
				for(String id : docid.split(",")){
					dv.setDocShareByDoc(id);
				}
			}catch(Exception e){
			}
		}
	}
	
	
	/**
	 * 获取权限
	 * @author wangqs
	 * @params user-当前人，isBatch-是否是批量调整，docid-文档
	 * */
	public Map<String,Object> getShareCondition(User user,boolean isBatch,String docid){
		return getShareCondition(user,isBatch,docid);
	}
	
	/**
	 * 获取权限
	 * @author wangqs
	 * @params user-当前人，isBatch-是否是批量调整，docid-文档,iscooper-是否是协同编辑
	 * */
	public Map<String,Object> getShareCondition(User user,boolean isBatch,boolean iscooper,String docid){
		Map<String,Object> apidatas = new HashMap<String,Object>();

		DocViewPermission dvps = new DocViewPermission();

		//其他模块参数集
		Map<String,Boolean> levelMap = dvps.getShareLevel(Util.getIntValue(docid,0),user,false);
		if(levelMap.get(DocViewPermission.CONTROL)||isBatch){
			sharelevel=3;
		}
		else{
			sharelevel=2;
		}
		
		
		int noDownload = 0;
	    int createUserType = 0;
		RecordSet rs = new RecordSet();
		if(!isBatch){
			rs.executeQuery("select d2.noDownload,d1.usertype from docdetail d1,DocSecCategory d2 where d1.seccategory=d2.id and d1.id=" + docid);
		    if(rs.next()){
		    	noDownload = Util.getIntValue(rs.getString("noDownload"),0);
		    	createUserType = Util.getIntValue(rs.getString("usertype"),0);
		    }
		}
	    
	    int isgoveproj = 0;
	    try{
	    	 Util.getIntValue(IsGovProj.getPath(),0);//0:非政务系统，1：政务系统
	    }catch(Exception e){
	    }
		
		int language = user.getLanguage();
		List<Object> conditions = new ArrayList<Object>();
		
		
		if(iscooper){
			noDownload = 1;
			sharelevel = 2;
		}

		if(CooperativeUtilForDoc.isColla(Util.getIntValue(docid))){
			sharelevel = 2;
		}
		
		//对象类型
		List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
		options.add(new SearchConditionOption(OBJ_TYPE_USER + "",SystemEnv.getHtmlLabelName(179,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_USER));
		options.add(new SearchConditionOption(OBJ_TYPE_SUB_COMPANY + "",SystemEnv.getHtmlLabelName(141,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_SUB_COMPANY));
		options.add(new SearchConditionOption(OBJ_TYPE_DEPARTMENT + "",SystemEnv.getHtmlLabelName(124,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_DEPARTMENT));
		options.add(new SearchConditionOption(OBJ_TYPE_POST + "",SystemEnv.getHtmlLabelName(6086,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_POST));
		options.add(new SearchConditionOption(OBJ_TYPE_ROLE + "",SystemEnv.getHtmlLabelName(122,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_ROLE));
		if(!new ManageDetachComInfo().appDetachDisableAll(user)){
			options.add(new SearchConditionOption(OBJ_TYPE_ALL + "",SystemEnv.getHtmlLabelName(1340,weaver.general.Util.getIntValue(language)),OBJ_TYPE_DEFAULT == OBJ_TYPE_ALL));
		}
		options.add(new SearchConditionOption(OBJ_TYPE_GROUP + "",SystemEnv.getHtmlLabelName(24002,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_GROUP));
		if(isgoveproj==0){
			options.add(new SearchConditionOption(OBJ_TYPE_CUSTOMER + "",SystemEnv.getHtmlLabelName(18647,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_CUSTOMER));
			options.add(new SearchConditionOption(OBJ_TYPE_CUSTOMER_TYPE + "",SystemEnv.getHtmlLabelName(1282,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_CUSTOMER_TYPE));
		}
		if (1 == createUserType){
			options.add(new SearchConditionOption(OBJ_TYPE_CREATER_SELF + "",SystemEnv.getHtmlLabelName(15079,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_CREATER_SELF));
			options.add(new SearchConditionOption(OBJ_TYPE_CREATER_MANAGER + "",SystemEnv.getHtmlLabelName(18583,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_CREATER_MANAGER));
			options.add(new SearchConditionOption(OBJ_TYPE_CREATER_ALL_MANAGER + "",SystemEnv.getHtmlLabelName(385205,weaver.general.Util.getIntValue(language)),OBJ_TYPE_DEFAULT == OBJ_TYPE_CREATER_ALL_MANAGER));
			options.add(new SearchConditionOption(OBJ_TYPE_CREATER_SUB_COMPANY + "",SystemEnv.getHtmlLabelName(18584,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_CREATER_SUB_COMPANY));
			options.add(new SearchConditionOption(OBJ_TYPE_CREATER_DEPARTMENT + "",SystemEnv.getHtmlLabelName(15081,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_CREATER_DEPARTMENT));
		}else if(!isBatch){
			options.add(new SearchConditionOption(OBJ_TYPE_CREATER_SELF_2 + "",SystemEnv.getHtmlLabelName(15079,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_CREATER_SELF_2));
			options.add(new SearchConditionOption(OBJ_TYPE_CREATER_MANAGER_2 + "",SystemEnv.getHtmlLabelName(18583,language),OBJ_TYPE_DEFAULT == OBJ_TYPE_CREATER_MANAGER_2));
		                                               
	   }
		SearchConditionItem optionType = new SearchConditionItem(ConditionType.SELECT,SystemEnv.getHtmlLabelName(21956,language)
				,new String []{OBJ_TYPE});
		optionType.setOptions(options);
		conditions.add(optionType);
		
		
		Map<String,Object> dataMap = new HashMap<String,Object>();
		conditions.add(dataMap);
		
		
		//人力资源
		List<Object> userOptList = new ArrayList<Object>();
		dataMap.put(OBJ_TYPE_USER + "",userOptList);
		List<Object> dataUserCondition = new ArrayList<Object>();
		SearchConditionItem  userCondition = new SearchConditionItem(ConditionType.BROWSER,SystemEnv.getHtmlLabelName(106,language),
				new String []{OBJ_ID});
		userCondition.setViewAttr(3);
		BrowserBean userBrowser = new BrowserBean();
		userBrowser.setType(BrowserType.USER_MULTI);
		userBrowser.setViewAttr(3);
		userBrowser.setTitle(SystemEnv.getHtmlLabelName(179,language));
		//开启了密级功能
		if(Util.getIntValue(docid,0)>0 && HrmClassifiedProtectionBiz.isOpenClassification()){
			String secretLevel=DocSecretLevelUtil.takeSecretLevelbyDocid(docid);
			Map<String, Object> dataParams = new HashMap<>();
			dataParams.put("classification",secretLevel);
			userBrowser.setDataParams(dataParams);
			userBrowser.setCompleteParams(dataParams);
		}

		userCondition.setBrowserConditionParam(userBrowser);
		dataUserCondition.add(userCondition);
		Object o = JSON.parseObject(JSON.toJSONString(dataUserCondition, SerializerFeature.DisableCircularReferenceDetect), List.class);
		dataUserCondition = (List<Object>) o;
		userOptList.add(dataUserCondition);
		userOptList.add(getPermissionMap(language,noDownload));
		
		new BaseBean().writeLog("<<<laiguo>>>");
		//分部
		List<Object> companyOptList = new ArrayList<Object>();
		dataMap.put(OBJ_TYPE_SUB_COMPANY + "",companyOptList);
		List<Object> dataCompanyCondition = new ArrayList<Object>();
		//SearchConditionItem  companyCondition = new SearchConditionItem(ConditionType.BROWSER,SystemEnv.getHtmlLabelName(106,language),
		//		new String []{OBJ_ID});
		//companyCondition.setValue(3);
		//BrowserBean companyBrowser = new BrowserBean();
		//companyBrowser.setType(BrowserType.SUBCOMPANY_MULTI);
		//companyBrowser.setViewAttr(3);
		//companyBrowser.setTitle(SystemEnv.getHtmlLabelName(141,language));
		//companyCondition.setBrowserConditionParam(companyBrowser);
		ConditionFactory conditionFactory = new ConditionFactory(user);
		SearchConditionItem searchConditionItem=conditionFactory.createCondition(ConditionType.BROWSER, "141", "subcompany","194");
		searchConditionItem.setViewAttr(3);
		searchConditionItem.getBrowserConditionParam().setViewAttr(3);
		dataCompanyCondition.add(searchConditionItem);
		dataCompanyCondition.add(getHasSub(language));
		companyOptList.add(dataCompanyCondition);
		companyOptList.add(getShareLevel(language));
		companyOptList.add(getPermissionMap(language,noDownload));

		
		//部门
		List<Object> departmentOptList = new ArrayList<Object>();
		dataMap.put(OBJ_TYPE_DEPARTMENT + "",departmentOptList);
		List<Object> dataDepartmentCondition = new ArrayList<Object>();
		//SearchConditionItem  departmentCondition = new SearchConditionItem(ConditionType.BROWSER,SystemEnv.getHtmlLabelName(106,language),
		//		new String []{OBJ_ID});
		//departmentCondition.setViewAttr(3);
		//BrowserBean departmentBrowser = new BrowserBean();
		//departmentBrowser.setType(BrowserType.DEPARTMENT_MULTI);
		//departmentBrowser.setViewAttr(3);
		//departmentBrowser.setTitle(SystemEnv.getHtmlLabelName(124,language));
		SearchConditionItem searchConditionItem2=conditionFactory.createCondition(ConditionType.BROWSER, "124", "department","57");
		searchConditionItem2.setViewAttr(3);
		searchConditionItem2.getBrowserConditionParam().setViewAttr(3);

		//departmentCondition.setBrowserConditionParam(searchConditionItem);
		dataDepartmentCondition.add(searchConditionItem2);
		dataDepartmentCondition.add(getHasSub(language));
		departmentOptList.add(dataDepartmentCondition);
		departmentOptList.add(getShareLevel(language));
		departmentOptList.add(getPermissionMap(language,noDownload));
		
		//岗位
		List<Object> postOptList = new ArrayList<Object>();
		dataMap.put(OBJ_TYPE_POST + "",postOptList);
		List<Object> dataPostCondition = new ArrayList<Object>();
		SearchConditionItem  postCondition = new SearchConditionItem(ConditionType.BROWSER,SystemEnv.getHtmlLabelName(106,language),
				new String []{OBJ_ID});
		postCondition.setViewAttr(3);
		BrowserBean postBrowser = new BrowserBean();
		postBrowser.setType(BrowserType.POST_MULTI);
		postBrowser.setViewAttr(3);
		postBrowser.setTitle(SystemEnv.getHtmlLabelName(6086,language));
		postCondition.setBrowserConditionParam(postBrowser);
		dataPostCondition.add(postCondition);
		
		List<SearchConditionOption> options3 = new ArrayList<SearchConditionOption>();
		options3.add(new SearchConditionOption(POST_LEVEL_ALL + "",SystemEnv.getHtmlLabelName(140,language),POST_LEVEL_ALL == POST_LEVEL_DEFAULT));
		options3.add(new SearchConditionOption(POST_LEVEL_SUB_COMPANY + "",SystemEnv.getHtmlLabelName(19437,language),POST_LEVEL_SUB_COMPANY == POST_LEVEL_DEFAULT));
		options3.add(new SearchConditionOption(POST_LEVEL_DEPARTMENT + "",SystemEnv.getHtmlLabelName(19438,language),POST_LEVEL_DEPARTMENT == POST_LEVEL_DEFAULT));
		List<Object> dataPostLevelCondition = new ArrayList<Object>();
		SearchConditionItem  postLevelCondition = new SearchConditionItem(ConditionType.SELECT_LINKAGE,SystemEnv.getHtmlLabelName(28169,weaver.general.Util.getIntValue(language)),
				new String []{POST_LEVEL});
		postLevelCondition.setOptions(options3);
		
		SearchConditionItem  subcompany = new SearchConditionItem(ConditionType.BROWSER,"",
				new String []{TARGET_OBJECT_ID});
		subcompany.setViewAttr(3);
		BrowserBean companyBrowser_p = new BrowserBean();
		companyBrowser_p.setType(BrowserType.SUBCOMPANY_MULTI);
		companyBrowser_p.setViewAttr(3);
		companyBrowser_p.setTitle(SystemEnv.getHtmlLabelName(141,language));
		subcompany.setBrowserConditionParam(companyBrowser_p);
		
		SearchConditionItem  department = new SearchConditionItem(ConditionType.BROWSER,"",
				new String []{TARGET_OBJECT_ID});
		department.setViewAttr(3);
		BrowserBean departmentBrowser_p = new BrowserBean();
		departmentBrowser_p.setType(BrowserType.DEPARTMENT_MULTI);
		departmentBrowser_p.setViewAttr(3);
		departmentBrowser_p.setTitle(SystemEnv.getHtmlLabelName(124,language));
		department.setBrowserConditionParam(departmentBrowser_p);
		
		Map<String,SearchConditionItem> targetObj = new HashMap<String,SearchConditionItem>();
		targetObj.put(POST_LEVEL_SUB_COMPANY + "", subcompany);
		targetObj.put(POST_LEVEL_DEPARTMENT + "", department);
		postLevelCondition.setSelectLinkageDatas(targetObj);
		dataPostLevelCondition.add(postLevelCondition);
		
		
		postOptList.add(dataPostCondition);
		postOptList.add(dataPostLevelCondition);
		postOptList.add(getPermissionMap(language,noDownload));
		
		
		//角色
		List<Object> roleOptList = new ArrayList<Object>();
		dataMap.put(OBJ_TYPE_ROLE + "",roleOptList);
		List<Object> dataRoleCondition = new ArrayList<Object>();
		SearchConditionItem  roleCondition = new SearchConditionItem(ConditionType.BROWSER,SystemEnv.getHtmlLabelName(106,language),
				new String []{OBJ_ID});
		roleCondition.setViewAttr(3);
		BrowserBean roleBrowser = new BrowserBean();
		roleBrowser.setType(BrowserType.ROLE_MULTI);
		roleBrowser.setViewAttr(3);
		roleBrowser.setTitle(SystemEnv.getHtmlLabelName(122,language));
		roleCondition.setBrowserConditionParam(roleBrowser);
		dataRoleCondition.add(roleCondition);
		
		List<SearchConditionOption> options4 = new ArrayList<SearchConditionOption>();
		options4.add(new SearchConditionOption(ROLE_LEVEL_DEPARTMENT + "",SystemEnv.getHtmlLabelName(124,language),ROLE_LEVEL_DEPARTMENT == ROLE_LEVEL_DEFAULT));
		options4.add(new SearchConditionOption(ROLE_LEVEL_SUB_COMPANY + "",SystemEnv.getHtmlLabelName(141,language),ROLE_LEVEL_SUB_COMPANY == ROLE_LEVEL_DEFAULT));
		options4.add(new SearchConditionOption(ROLE_LEVEL_ALL + "",SystemEnv.getHtmlLabelName(140,language),ROLE_LEVEL_ALL == ROLE_LEVEL_DEFAULT));
		SearchConditionItem roleLevelCondition = new SearchConditionItem(ConditionType.SELECT,SystemEnv.getHtmlLabelName(139,language),
				new String []{ROLE_LEVEL});
		roleLevelCondition.setOptions(options4);
		dataRoleCondition.add(roleLevelCondition);
		roleOptList.add(dataRoleCondition);
		roleOptList.add(getShareLevel(language));
		roleOptList.add(getPermissionMap(language,noDownload));

		
		//所有人
		List<Object> allOptList = new ArrayList<Object>();
		dataMap.put(OBJ_TYPE_ALL + "",allOptList);
		allOptList.add(getShareLevel(language));
		allOptList.add(getPermissionMap(language,noDownload));
		
		//群组
		List<Object> groupOptList = new ArrayList<Object>();
		dataMap.put(OBJ_TYPE_GROUP + "",groupOptList);
		List<Object> dataGroupCondition = new ArrayList<Object>();
		SearchConditionItem  groupCondition = new SearchConditionItem(ConditionType.BROWSER,SystemEnv.getHtmlLabelName(106,language),
				new String []{OBJ_ID});
		groupCondition.setViewAttr(3);
		BrowserBean groupBrowser = new BrowserBean();
		groupBrowser.setType(BrowserType.GROUP_MULTI);
		groupBrowser.setViewAttr(3);
		groupBrowser.setTitle(SystemEnv.getHtmlLabelName(1340,weaver.general.Util.getIntValue(language)));
		groupBrowser.setTitle(SystemEnv.getHtmlLabelName(24002,language));
		groupCondition.setBrowserConditionParam(groupBrowser);
		dataGroupCondition.add(groupCondition);
		
		groupOptList.add(dataGroupCondition);
		groupOptList.add(getShareLevel(language));
		groupOptList.add(getPermissionMap(language,noDownload));
		
		if(isgoveproj==0){
			//指定客户
			List<Object> customerOptList = new ArrayList<Object>();
			dataMap.put(OBJ_TYPE_CUSTOMER + "",customerOptList);
			List<Object> dataCustomerCondition = new ArrayList<Object>();
			SearchConditionItem  customerCondition = new SearchConditionItem(ConditionType.BROWSER,SystemEnv.getHtmlLabelName(106,language),
					new String []{OBJ_ID});
			customerCondition.setViewAttr(3);
			BrowserBean customerBrowser = new BrowserBean();
			customerBrowser.setType(BrowserType.CUSTOMER_MULTI);
			customerBrowser.setViewAttr(3);
			customerBrowser.setTitle(SystemEnv.getHtmlLabelName(136,language));
			customerCondition.setBrowserConditionParam(customerBrowser);
			dataCustomerCondition.add(customerCondition);
			customerOptList.add(dataCustomerCondition);
			customerOptList.add(getPermissionMap(language,noDownload));
		
			//客户类型
			List<Object> customerTypeOptList = new ArrayList<Object>();
			dataMap.put(OBJ_TYPE_CUSTOMER_TYPE + "",customerTypeOptList);
			List<Object> dataCustomerTypeCondition = new ArrayList<Object>();
			SearchConditionItem  customerTypeCondition = new SearchConditionItem(ConditionType.SELECT,SystemEnv.getHtmlLabelName(106,language),
					new String []{OBJ_ID});
			List<SearchConditionOption> options_ct = new ArrayList<SearchConditionOption>();
			CustomerTypeComInfo ctci = new CustomerTypeComInfo();
			int i = 0;
			while(ctci.next()){
				String curid=ctci.getCustomerTypeid();
				String curname=ctci.getCustomerTypename();
				String optionvalue="-"+curid;
				options_ct.add(new SearchConditionOption(optionvalue,curname,i == 0));
				i++;
			}
			
			customerTypeCondition.setOptions(options_ct);
			dataCustomerTypeCondition.add(customerTypeCondition);
			customerTypeOptList.add(dataCustomerTypeCondition);
			customerTypeOptList.add(getShareLevel(language));
			customerTypeOptList.add(getPermissionMap(language,noDownload));
			
		}
		
		if (1 == createUserType){
			//创建人本人
			List<Object> createrSelfOptList = new ArrayList<Object>();
			dataMap.put(OBJ_TYPE_CREATER_SELF + "",createrSelfOptList);
			createrSelfOptList.add(getPermissionMap(language,noDownload));
			
			List<Map<String,String>> dimensions = new ArrayList<Map<String,String>>();
			
			CompanyVirtualComInfo cvci = new CompanyVirtualComInfo();
			if(cvci.getCompanyNum()>0){
				
				// 行政组织 
				Map<String,String> dimension0 = new HashMap<String,String>();
				dimension0.put("id", "0");
				dimension0.put("name", SystemEnv.getHtmlLabelName(83179,user.getLanguage()));
				dimensions.add(dimension0);
				
				cvci.setTofirstRow();
				while(cvci.next()){
					Map<String,String> dimension = new HashMap<String,String>();
					dimensions.add(dimension);
					dimension.put("id", cvci.getCompanyid());
					dimension.put("name", cvci.getVirtualType());
				}
			}
			
			
			//创建人直接上级
			List<Object> createrManagerOptList = new ArrayList<Object>();
			dataMap.put(OBJ_TYPE_CREATER_MANAGER + "",createrManagerOptList);
			if(dimensions.size() > 0){
				createrManagerOptList.add(getDimensionMap(language,dimensions));
			}
			createrManagerOptList.add(getPermissionMap(language,noDownload));
			
			//创建人所有上级
			List<Object> createrAllManagerOptList = new ArrayList<Object>();
			dataMap.put(OBJ_TYPE_CREATER_ALL_MANAGER + "",createrAllManagerOptList);
			if(dimensions.size() > 0){
				createrAllManagerOptList.add(getDimensionMap(language,dimensions));
			}
			createrAllManagerOptList.add(getPermissionMap(language,noDownload));
			
			//创建人本分部
			List<Object> createrSubCompanyOptList = new ArrayList<Object>();
			dataMap.put(OBJ_TYPE_CREATER_SUB_COMPANY + "",createrSubCompanyOptList);
			if(dimensions.size() > 0){
				createrSubCompanyOptList.add(getDimensionMap(language,dimensions));
			}
			createrSubCompanyOptList.add(getShareLevel(language));
			createrSubCompanyOptList.add(getPermissionMap(language,noDownload));
			
			//创建人本部门
			List<Object> createrDepartmentOptList = new ArrayList<Object>();
			dataMap.put(OBJ_TYPE_CREATER_DEPARTMENT + "",createrDepartmentOptList);
			if(dimensions.size() > 0){
				createrDepartmentOptList.add(getDimensionMap(language,dimensions));
			}
			createrDepartmentOptList.add(getShareLevel(language));
			createrDepartmentOptList.add(getPermissionMap(language,noDownload));
			
		}else{
			
		}
		
		apidatas.put("conditions",conditions);
		return apidatas;
	}
	
	/**
	 * 权限
	 * */
	public List<Object> getPermissionMap(int language,int noDownload){
		List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
		options.add(new SearchConditionOption(SEC_LEVEL_VIEW + "",SystemEnv.getHtmlLabelName(367,language),SEC_LEVEL_VIEW == SEC_LEVEL_DEFAULT,true));
		options.add(new SearchConditionOption(SEC_LEVEL_EDIT + "",SystemEnv.getHtmlLabelName(93,language),SEC_LEVEL_EDIT == SEC_LEVEL_DEFAULT,true));
		if(sharelevel>2){
			options.add(new SearchConditionOption(SEC_LEVEL_ALL + "",SystemEnv.getHtmlLabelName(17874,language),SEC_LEVEL_ALL == SEC_LEVEL_DEFAULT,true));
		}

		List<Object> dataPermissionCondition = new ArrayList<Object>();
		SearchConditionItem  secLevelCondition = new SearchConditionItem(ConditionType.SELECT_LINKAGE,SystemEnv.getHtmlLabelName(385,language),
				new String []{SEC_LEVEL});
		secLevelCondition.setOptions(options);
		SearchConditionItem  downloadCondition = new SearchConditionItem(ConditionType.CHECKBOX,SystemEnv.getHtmlLabelName(23733,language),
				new String []{DOWNLOAD});
		if(noDownload == 1){
			downloadCondition.setViewAttr(1);
		}else{
			downloadCondition.setValue("1");
		}
		
		Map<String,SearchConditionItem> selectLinkageDatas = new HashMap<String,SearchConditionItem>();
		if(noDownload != 1){
			selectLinkageDatas.put(SEC_LEVEL_VIEW + "", downloadCondition);
		}
			
		secLevelCondition.setSelectLinkageDatas(selectLinkageDatas);
		
		dataPermissionCondition.add(secLevelCondition);
		//dataPermissionCondition.add(downloadCondition);
		return dataPermissionCondition;
	}
	
	/**
	 * 含下级
	 * */
	public SearchConditionItem getHasSub(int language){
		SearchConditionItem  hasSub = new SearchConditionItem(ConditionType.CHECKBOX,SystemEnv.getHtmlLabelName(125963,weaver.general.Util.getIntValue(language)),
				new String []{HAS_SUB});
		return hasSub;
	}
	
	/**
	 * 维度
	 * */
	public List<Object> getDimensionMap(int language,List<Map<String,String>> dimensions){
		List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
		
		int i = 0;
		for(Map<String,String> map : dimensions){
			options.add(new SearchConditionOption(map.get("id"),map.get("name"),i == 0));
			i++;
		}
		
		SearchConditionItem  dimension = new SearchConditionItem(ConditionType.SELECT,SystemEnv.getHtmlLabelName(34069,language),
				new String []{CREATER_ORGID});
		dimension.setOptions(options);
		
		List<Object> dimensionCondition = new ArrayList<Object>();
		dimensionCondition.add(dimension);
		
		return dimensionCondition;
	}
	
	/**
	 * 安全级别
	 * */
	public List<Object> getShareLevel( int language){
		List<Object> dataLevelCondition = new ArrayList<Object>();
		SearchConditionItem  level = new SearchConditionItem(ConditionType.INPUT_INTERVAL,SystemEnv.getHtmlLabelName(683,language),
				new String []{FROM_LEVEL,TO_LEVEL});
		List<Integer> values = new ArrayList<Integer>();
		values.add(SEC_LEVEL_FROM);
		values.add(SEC_LEVEL_TO);
		level.setValue(values);
		dataLevelCondition.add(level);
		return dataLevelCondition;
	}
	
	/**
	 * 人力资源
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 * 			userids-用户id集合，逗号隔开（被赋予权限对象）
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			download-是否可下载		 			
	 * */
	public void addShareForUser(User user,int docid,String userids,int seclevel,boolean download){
		RecordSet rs = new RecordSet();
		for(String userid : userids.split(",")){
			if(userid.isEmpty()) continue;
			String sql = "insert into DocShare(docid,sharetype,sharelevel,userid,downloadlevel) values("+
				docid+","+OBJ_TYPE_USER+","+seclevel+","+userid+","+(download?1:0)+")";
	
			rs.execute(sql);
		}
		
	}
	/**
	 * 分部
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 * 			companyids-分部id集合，逗号隔开（被赋予权限对象）
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			fromlevel-最低安全级别
	 *			tolevel-最高安全级别
	 *			containsSub-是否含下级
	 *			download-是否可下载	
	 * */
	public void addShareForSubCompany(User user,int docid,String companyids,int seclevel,int fromlevel,int tolevel,boolean containsSub,boolean download){
		RecordSet rs = new RecordSet();
		for(String companyid : companyids.split(",")){
			if(companyid.isEmpty()) continue;
			String sql = "insert into DocShare(docid,sharetype,seclevel,sharelevel,subcompanyid,downloadlevel,seclevelmax,includesub) values("+
				docid+","+OBJ_TYPE_SUB_COMPANY+","+fromlevel+","+seclevel+"," + companyid + ","+(download?1:0)+","+tolevel+",'"+(containsSub ? 1 : 0)+"')";
			rs.execute(sql);
		}
	}
	/**
	 * 部门
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 * 			departmentids-部门id集合，逗号隔开（被赋予权限对象）
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			fromlevel-最低安全级别
	 *			tolevel-最高安全级别
	 *			containsSub-是否含下级
	 *			download-是否可下载	
	 * */
	public void addShareForDepartment(User user,int docid,String departmentids,int seclevel,int fromlevel,int tolevel,boolean containsSub,boolean download){
		RecordSet rs = new RecordSet();
		for(String departmentid : departmentids.split(",")){
			String sql = "insert into DocShare(docid,sharetype,seclevel,sharelevel,departmentid,downloadlevel,seclevelmax,includesub) values("+
				docid+","+OBJ_TYPE_DEPARTMENT+","+fromlevel+","+seclevel+"," + departmentid + ","+(download?1:0)+","+tolevel+",'"+(containsSub ? 1 : 0)+"')";
			rs.execute(sql);
		}
	}
	/**
	 * 岗位
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 * 			postids-岗位id集合，逗号隔开（被赋予权限对象）
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			level-岗位级别（1-总部，2-指定分部，3-指定部门）
	 *			tagetids-指定分部（部门）id集合
	 *			download-是否可下载	
	 * */
	public void addShareForPost(User user,int docid,String postids,int seclevel,int level,String tagetids,boolean download){
		RecordSet rs = new RecordSet();
		for(String postid : postids.split(",")){
			String columns = "docid,sharetype,sharelevel,downloadlevel,jobids,joblevel";
			String values = docid+","+OBJ_TYPE_POST+","+seclevel+","+(download?1:0)+",'"+postid+"','" + level + "'";
			
			
			if(level == POST_LEVEL_SUB_COMPANY){
				columns += ",jobsubcompany";
			}else if(level == POST_LEVEL_DEPARTMENT){
				columns += ",jobdepartment";
			}
			
			if(level == POST_LEVEL_ALL){
				rs.execute("insert into DocShare(" + columns + ") values(" + values + ")");
			}else{
				for(String targetid : tagetids.split(",")){
					if(targetid.isEmpty()) continue;
					rs.execute("insert into DocShare(" + columns + ") values(" + values + ",'" + targetid + "')");
				}
			}
		}
	}
	
	/**
	 * 角色
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 * 			roleids-角色id集合，逗号隔开（被赋予权限对象）
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			level-级别（1-总部，2-分部，3-部门）
	 *			fromlevel-最低安全级别
	 *			tolevel-最高安全级别
	 *			download-是否可下载	
	 * */
	public void addShareForRole(User user,int docid,String roleids,int seclevel,int level,int fromlevel,int tolevel,boolean download){
		RecordSet rs = new RecordSet();
		for(String roleid : roleids.split(",")){
			if(roleid.isEmpty()) continue;
			String sql = "insert into DocShare(docid,sharetype,seclevel,sharelevel,roleid,downloadlevel,seclevelmax,rolelevel) values("+
				docid+","+OBJ_TYPE_ROLE+","+fromlevel+","+seclevel+"," + roleid + ","+(download?1:0)+","+tolevel+"," + level + ")";
			rs.execute(sql);
		}
	}
	
	/**
	 * 群组
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 * 			groupids-群组id集合，逗号隔开（被赋予权限对象）
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			fromlevel-最低安全级别
	 *			tolevel-最高安全级别
	 *			download-是否可下载	
	 * */
	public void addShareForGroup(User user,int docid,String groupids,int seclevel,int fromlevel,int tolevel,boolean download){
		RecordSet rs = new RecordSet();
		for(String groupid : groupids.split(",")){
			if(groupid.isEmpty()) continue;
			String sql = "insert into DocShare(docid,sharetype,seclevel,sharelevel,downloadlevel,seclevelmax,orgGroupId) values("+
				docid+","+OBJ_TYPE_GROUP+","+fromlevel+","+seclevel+","+(download?1:0)+","+tolevel+"," + groupid +")";
			rs.execute(sql);
		}
	}
	
	/**
	 * 所有人
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			fromlevel-最低安全级别
	 *			tolevel-最高安全级别
	 *			download-是否可下载	
	 * */
	public void addShareForAll(User user,int docid,int seclevel,int fromlevel,int tolevel,boolean download){
		RecordSet rs = new RecordSet();
		String sql = "insert into DocShare(docid,sharetype,seclevel,sharelevel,downloadlevel,seclevelmax,foralluser) values("+
			docid+","+OBJ_TYPE_ALL+","+fromlevel+","+seclevel+","+(download?1:0)+","+tolevel+",1)";
		rs.execute(sql);
	}
	
	
	/**
	 * 指定客户
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 * 			crmids-客户id集合，逗号隔开（被赋予权限对象）
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			download-是否可下载	
	 * */
	public void addShareForCustomer(User user,int docid,String crmids,int seclevel,boolean download){
		RecordSet rs = new RecordSet();
		for(String crmid : crmids.split(",")){
			if(crmid.isEmpty()) continue;
			String sql = "insert into DocShare(docid,sharetype,sharelevel,downloadlevel,crmid) values("+
				docid+","+OBJ_TYPE_CUSTOMER+","+seclevel+","+(download?1:0)+"," + crmid + ")";
			rs.execute(sql);
		}
	}
	
	/**
	 * 客户类型
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 * 			crmtypeid - 负的客户类型id(-id) 
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			fromlevel-最低安全级别
	 *			tolevel-最高安全级别
	 *			download-是否可下载	
	 * */
	public void addShareForCustomerType(User user,int docid,String crmtypeid,int seclevel,int fromlevel,int tolevel,boolean download){
		RecordSet rs = new RecordSet();
		String sql = "insert into DocShare(docid,sharetype,seclevel,sharelevel,downloadlevel,seclevelmax) values("+
			docid+",'"+crmtypeid+"',"+fromlevel+","+seclevel+","+(download?1:0)+","+tolevel+")";
		rs.execute(sql);
	}
	
	/**
	 * 创建人本人
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			download-是否可下载	
	 * */
	public void addShareForCreaterSelf(User user,int docid,int seclevel,boolean download){
		RecordSet rs = new RecordSet();
		
		String sql = "insert into DocShare(docid,sharetype,sharelevel,downloadlevel,userid) select "+
			docid+","+OBJ_TYPE_CREATER_SELF+","+seclevel+","+(download?1:0)+",doccreaterid from DocDetail where id=" + docid;
		rs.execute(sql);
	}
	
	/**
	 * 创建人本人（文档创建人为客户）
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			download-是否可下载	
	 * */
	public void addShareForCreaterSelf2(User user,int docid,int seclevel,boolean download){
		RecordSet rs = new RecordSet();
		String sql = "insert into DocShare(docid,sharetype,sharelevel,downloadlevel,userid) select "+
			docid+","+OBJ_TYPE_CREATER_SELF_2+","+seclevel+","+(download?1:0)+",doccreaterid from DocDetail where id=" + docid;
		rs.execute(sql);
	}
	
	/**
	 * 创建人直接上级
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			orgid-维度
	 *			download-是否可下载	
	 * */
	public void addShareForCreaterManager(User user,int docid,String orgid,int seclevel,boolean download){
		RecordSet rs = new RecordSet();
		String sql = "insert into DocShare(docid,sharetype,sharelevel,downloadlevel,orgid,userid) select "+
			docid+","+OBJ_TYPE_CREATER_MANAGER+","+seclevel+","+(download?1:0)+",'" + orgid + "',doccreaterid from DocDetail where id=" + docid;
		rs.execute(sql);
	}
	
	/**
	 * 创建人直接上级（文档创建人为客户）
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			orgid-维度
	 *			download-是否可下载	
	 * */
	public void addShareForCreaterManager2(User user,int docid,String orgid,int seclevel,boolean download){
		RecordSet rs = new RecordSet();
		String sql = "insert into DocShare(docid,sharetype,sharelevel,downloadlevel,orgid,userid) select "+
			docid+","+OBJ_TYPE_CREATER_MANAGER_2+","+seclevel+","+(download?1:0)+",'" + orgid + "',doccreaterid from DocDetail where id=" + docid;
		rs.execute(sql);
	}
	
	/**
	 * 创建人所有上级
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			orgid-维度
	 *			download-是否可下载	
	 * */
	public void addShareForCreaterAllManager(User user,int docid,String orgid,int seclevel,boolean download){
		RecordSet rs = new RecordSet();
		String sql = "insert into DocShare(docid,sharetype,sharelevel,downloadlevel,orgid,allmanagers,userid) select "+
			docid+","+OBJ_TYPE_CREATER_MANAGER+","+seclevel+","+(download?1:0)+",'" + orgid + "','1',doccreaterid from DocDetail where id=" + docid;
		rs.execute(sql);
	}
	
	/**
	 * 创建人本分部
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			orgid-维度
	 *			fromlevel-最低安全级别
	 *			tolevel-最高安全级别
	 *			download-是否可下载	
	 * */
	public void addShareForCreaterSubCompany(User user,int docid,String orgid,int seclevel,int fromlevel,int tolevel,boolean download){
		RecordSet rs = new RecordSet();
		String sql = "insert into DocShare(docid,sharetype,sharelevel,seclevel,seclevelmax,downloadlevel,orgid,userid) select "+
			docid+","+OBJ_TYPE_CREATER_SUB_COMPANY+","+seclevel+","+fromlevel+","+tolevel+","+(download?1:0)+",'" + orgid + "',doccreaterid from DocDetail where id=" + docid;
		rs.execute(sql);
	}
	
	
	/**
	 * 创建人本部门
	 * @author wangqs
	 * @params 	user-当前用户
	 * 			docid-文档id
	 *			seclevel-权限（1-查看；2-编辑，3-完全控制）	
	 *			orgid-维度
	 *			fromlevel-最低安全级别
	 *			tolevel-最高安全级别
	 *			download-是否可下载	
	 * */
	public void addShareForCreaterDepartment(User user,int docid,String orgid,int seclevel,int fromlevel,int tolevel,boolean download){
		RecordSet rs = new RecordSet();
		String sql = "insert into DocShare(docid,sharetype,sharelevel,seclevel,seclevelmax,downloadlevel,orgid,userid) select "+
			docid+","+OBJ_TYPE_CREATER_DEPARTMENT+","+seclevel+","+fromlevel+","+tolevel+","+(download?1:0)+",'" + orgid + "',doccreaterid from DocDetail where id=" + docid;
		rs.execute(sql);
	}
	
	
	public ArrayList<Map<String,String>> getShareList(int stringType, int docId,
			String needCheckbox, int userLanguage,boolean isMobile) throws Exception{
		
		
		JobTitlesComInfo jbcom=new JobTitlesComInfo();
		CompanyVirtualComInfo cvc=new CompanyVirtualComInfo();
		ResourceComInfo rcc = new ResourceComInfo();
		KnowledgeTransMethod knotm = new KnowledgeTransMethod();
		SubCompanyComInfo scci = new SubCompanyComInfo();
		DepartmentComInfo dci = new DepartmentComInfo();
		RolesComInfo rci = new RolesComInfo();
		CustomerTypeComInfo ctci = new CustomerTypeComInfo();
		CustomerInfoComInfo cici = new CustomerInfoComInfo();
		HrmOrgGroupComInfo hogci = new HrmOrgGroupComInfo();
		
		DocSptm ds = new DocSptm();
		
		
		ArrayList<Map<String,String>> returnList=new ArrayList<Map<String,String>>();
		//String shareTRString = "";
		String sqlStr = "";
		String isAllowModiMShare = "0";
		String isAllowModiNMShare = "0";

		int hasVirtualCom = 0 ;
		if(cvc.getCompanyNum()>0){
          hasVirtualCom=1;
        }
		RecordSet rs = new RecordSet();
		RecordSet rs2 = new RecordSet();

		rs.executeQuery("select d2.allownModiMshareL,d2.allownModiMshareW,d2.shareable from docdetail d1,DocSecCategory d2 where d1.seccategory=d2.id and d1.id=?"
						,docId);
		if (rs.next()) {
			isAllowModiMShare = Util.null2String(rs.getString("allownModiMshareL"));
			isAllowModiNMShare = Util.null2String(rs.getString("shareable"));
		}
		if (stringType == 1) { // 与创建人相关的默认共享 (内部)
			sqlStr = "select * from docshare where docid=?"
					+ " and ( (sharetype between 80 and 85 and isSecDefaultShare='1' and sharetype!=89 )or( sharetype=11 and isSecDefaultShare='1' and  isSecDefaultShare='1' and sharetype!=89 ))order by  issecdefaultshare desc,sharetype";
			rs.executeQuery(sqlStr,docId);
			while (rs.next()) {
				
				int orgid = Util.getIntValue(rs.getString("orgid"),0);
				int seclevelmax = Util.getIntValue(rs.getString("seclevelmax"),255);
				String includesub = Util.null2String(rs.getString("includesub"));
				String allmanagers=Util.null2String(rs.getString("allmanagers"));

				String operategrouppar = userLanguage+"+1+"+orgid+"+"+hasVirtualCom;
				String shareName = "";
				String shareRealName = "";
				String shareRealLevel = "";
				String shareRealType = "";
				String isDisabled = "";


				int shareId = rs.getInt("id");
				int shareType = rs.getInt("sharetype");
				int shareUserId = rs.getInt("userid");
				int shareLevel = rs.getInt("sharelevel");
				int downloadlevel = Util.getIntValue(rs.getString("downloadlevel"), 0);//TD12005
				String secLevel = Util.null2String(rs.getString("seclevel"));
				String isSecDefaultShare = Util.null2String(rs.getString("isSecDefaultShare"));
				if (!"1".equals(isAllowModiMShare) && "1".equals(isSecDefaultShare)) {
					isDisabled = " disabled ";
				}
				
				String joblevel=Util.null2String(rs.getString("joblevel"));
				String jobids=Util.null2String(rs.getString("jobids"));
				
				String includesubDes=SystemEnv.getHtmlLabelName(10000010,userLanguage);
		        if("1".equals(includesub)){
			        includesubDes=SystemEnv.getHtmlLabelName(125963,userLanguage);
			     }
				
				switch (shareType) {
				case 80: // 与创建人本人相关
					shareName = knotm.getShareTypeNew("1",operategrouppar);
					shareRealName = ds.getHrmCard(shareUserId + "");
					if(isMobile){
						shareRealName = rcc.getResourcename(shareUserId + "");
					}
					shareRealLevel = "";
					break;
				case 81: // 与创建人直接上级相关

                    if (orgid == 0) {
                        if (allmanagers.equals("1")) {
                            shareName = knotm.getShareTypeNew("3", operategrouppar);
                            shareRealName = ds.getHrmCard(rcc.getManagersIDs("" + shareUserId));
							if(isMobile){
								shareRealName = ds.getHrmCard(rcc.getManagersIDs("" + shareUserId),isMobile);
							}
                            if ("".equals(rcc.getManagersIDs("" + shareUserId) + "") || "0".equals(rcc.getManagersIDs("" + shareUserId) + ""))
                                continue;
                        } else {
                            shareName = knotm.getShareTypeNew("2", operategrouppar);
//                            shareRealName = rcc.getLastname(rcc.getManagerID("" + shareUserId));
////                            if ("".equals(shareRealName))
////                                continue;
                            shareRealName = ds.getHrmCard(rcc.getManagerID("" + shareUserId));
							if(isMobile){
								shareRealName = ds.getHrmCard(rcc.getManagerID("" + shareUserId),isMobile);
							}

                        }
                    } else if (orgid < 0) {
                        String allmtem = "";
                        if (allmanagers.equals("1")) {
                            shareName = knotm.getShareTypeNew("3", operategrouppar);
                            rs2.executeQuery("select * from HrmResourceVirtual where virtualtype=? and resourceid=?", orgid, shareUserId);
                            if (rs2.next()) {
                                allmtem = rs2.getString("managerstr");
                                shareRealName += ds.getHrmCard(allmtem + "");
								if(isMobile){
									shareRealName += ds.getHrmCard(allmtem + "",isMobile);
								}
                            }
                        } else {
                            shareName = knotm.getShareTypeNew("2", operategrouppar);
                            rs2.executeQuery("select * from HrmResourceVirtual where virtualtype=? and resourceid=?", orgid, shareUserId);
                            if (rs2.next()) {
                                allmtem = rs2.getString("managerid");
                                shareRealName = ds.getHrmCard(allmtem);
								if(isMobile){
									shareRealName =  ds.getHrmCard(allmtem,isMobile);
								}
                            }
                        }

                        if ("".equals(allmtem))
                            continue;

                    }
                    if ("".equals(shareRealName))
                        continue;
                    shareRealLevel = "";

                    break;

				case 84: // 与创建人分部相关
					shareName =  knotm.getShareTypeNew("4",operategrouppar);
					String departmentId = rcc.getDepartmentID("" + shareUserId);
					String subCompanyName = scci.getSubCompanyname(dci.getSubcompanyid1(departmentId));
					
					
					if(orgid==0){
						shareRealName = subCompanyName;
						if ("".equals(shareRealName))
							continue;
						if(!isMobile){
							//shareRealName += "(" + includesubDes + ")";
							shareRealName = ds.getCompanyLink(dci.getSubcompanyid1(departmentId),shareRealName);

						}
					}else if(orgid<0){
					
					 rs2.executeQuery("select * from HrmResourceVirtual where virtualtype=? and resourceid=?",orgid,shareUserId);
					 if(rs2.next()){
						 shareRealName = scci.getSubCompanyname(rs2.getString("subcompanyid"));
						 if ("".equals(shareRealName))
							continue;
						 if(!isMobile){
							 shareRealName += "(" + includesubDes + ")";
							 shareRealName = ds.getCompanyLink(rs2.getString("subcompanyid"),shareRealName);
						 }

					 }
					}
					  if ("".equals(shareRealName))
						continue;
					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;
				case 85: // 与创建人部门相关
					shareName =  knotm.getShareTypeNew("5",operategrouppar);
					departmentId = rcc.getDepartmentID("" + shareUserId);
					String departmentName = dci.getDepartmentname(departmentId);

					String subcompanyid = rcc.getSubCompanyID("" + shareUserId);
					String subcompanyname = scci.getSubcompanyname(subcompanyid);

					if(orgid==0){
						shareRealName = departmentName+"["+subcompanyname+"]";
						if ("".equals(departmentName))
							continue;
						if(!isMobile){
							//shareRealName += "(" + includesubDes + ")";
							shareRealName = ds.getDepartmentLink(departmentId,shareRealName);
						}


					}else if(orgid<0){
					
					 rs2.executeQuery("select * from HrmResourceVirtual where virtualtype=? and resourceid=?",orgid,shareUserId);
					 if(rs2.next()){
						 shareRealName = dci.getDepartmentname(rs2.getString("departmentid"));
						 if ("".equals(shareRealName))
							continue;
						 if(!isMobile){
							 //shareRealName += "(" + includesubDes + ")";
							 shareRealName = ds.getDepartmentLink(rs2.getString("departmentid"),shareRealName);
						 }

					 }
					 
					
					}
					  if ("".equals(shareRealName))
						continue;
					shareRealLevel = secLevel+"-"+seclevelmax ;
					break;
					 
				  case 11: // 与创建人岗位相关
					shareName =  SystemEnv.getHtmlLabelName(126610,userLanguage);					
					shareRealName = jbcom.getJobTitlesname(jobids) +"/";
					if ("".equals(jbcom.getJobTitlesname(jobids))){
						continue;
					}
			       if(joblevel.equals("1")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(140,userLanguage);
	 			   }
			
	 			   if(joblevel.equals("2")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(21837,userLanguage);
				   }			
	 			   if(joblevel.equals("3")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(126607,userLanguage);
				   }
				   if(joblevel.equals("4")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(126608,userLanguage);
				   }
				   if(joblevel.equals("5")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(30792,userLanguage);
				   }
				   if(joblevel.equals("6")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(19436,userLanguage);
				   }
				   if(joblevel.equals("7")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(27189,userLanguage);
				   }

  	
				    if ("".equals(shareRealName))
						continue;
					shareRealLevel ="";
					break;


                

				}
				if (shareLevel == 1)
					shareRealType = SystemEnv.getHtmlLabelName(367,
							userLanguage);
				else if (shareLevel == 2)
					shareRealType = SystemEnv.getHtmlLabelName(93,
							userLanguage);
				else if (shareLevel == 3)
					shareRealType = SystemEnv.getHtmlLabelName(17874,
							userLanguage);
				
				
				String downloadlevelName = "";
				if(shareLevel==1){
					downloadlevelName = downloadlevel == 1 ? SystemEnv.getHtmlLabelName(23733, userLanguage) :SystemEnv.getHtmlLabelName(23734, userLanguage);
				}
				if(isMobile){
					shareRealName = WaterMarkUtil.delHTMLTag(shareRealName);
				}
				Map<String,String> ht=new HashMap<String,String>();
				ht.put("shareId", ""+shareId);
				ht.put("shareName", shareName);
				ht.put("shareRealLevel", shareRealLevel);
				ht.put("shareRealName", shareRealName);
				ht.put("shareRealType", shareRealType);
				ht.put("downloadlevelName", downloadlevelName);
				ht.put("downloadlevel", ""+downloadlevel);
				
				ht.put("type",SystemEnv.getHtmlLabelName(15059, userLanguage));
				
				
				
				if ("true".equalsIgnoreCase(needCheckbox))
					ht.put("chk", ""+isDisabled);
				
				returnList.add(ht);
			}
			
		} else if (stringType == 2) { // 与创建人本人无关的默认共享
			sqlStr = "select * from docshare where docid=? "
					+ " and sharetype between 1 and 79  and isSecDefaultShare='1' and  sharetype !=11  order by  issecdefaultshare desc,sharetype";
			rs.executeQuery(sqlStr,docId);
			while (rs.next()) {
				int seclevelmax = Util.getIntValue(rs.getString("seclevelmax"),255);
				int includesub = Util.getIntValue(rs.getString("includesub"),0);

				String joblevel=Util.null2String(rs.getString("joblevel"));
				String jobdepartment=Util.null2String(rs.getString("jobdepartment"));
				String jobsubcompany=Util.null2String(rs.getString("jobsubcompany"));
				String jobids=Util.null2String(rs.getString("jobids"));

				String includesubDes=SystemEnv.getHtmlLabelName(10000010,userLanguage);
		        if(includesub==1){
			        includesubDes=SystemEnv.getHtmlLabelName(125963,userLanguage);
			     }

				String shareName = "";
				String shareRealName = "";
				String shareRealLevel = "";
				String shareRealType = "";
				String isDisabled = "";

				int shareId = rs.getInt("id");
				int shareType = rs.getInt("sharetype");
				int shareUserId = rs.getInt("userid");
				int shareCrmId = rs.getInt("crmid");
				int shareLevel = rs.getInt("sharelevel");
				int downloadlevel = Util.getIntValue(rs.getString("downloadlevel"), 0);//TD12005
				
				String secLevel = Util.null2String(rs.getString("seclevel"));
				String isSecDefaultShare = Util.null2String(rs.getString("isSecDefaultShare"));
				if (!"1".equals(isAllowModiMShare)
						&& "1".equals(isSecDefaultShare)) {
					isDisabled = " disabled ";
				}
				switch (shareType) {
				case 1: // 人力资源
					shareName = SystemEnv.getHtmlLabelName(179, userLanguage);
					shareRealName = rcc.getLastname("" + shareUserId);
					if ("".equals(shareRealName))
						continue;
					if(!isMobile){
						shareRealName = ds.getHrmCard(shareUserId + "");
					}

					break;
				case 2: // 分部
					int subcompanyId = rs.getInt("subcompanyid");
					shareName = SystemEnv.getHtmlLabelName(141, userLanguage);									
					shareRealName = scci.getSubCompanyname("" + subcompanyId)+"("+includesubDes+")";
					if ("".equals(shareRealName))
						continue;
					if(!isMobile){
						shareRealName = ds.getCompanyLink(subcompanyId + "",shareRealName);
					}
					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;
				case 3: // 部门
					int departmentId = rs.getInt("departmentid");
					shareName = SystemEnv.getHtmlLabelName(18939, userLanguage);
					shareRealName = dci.getDepartmentname("" + departmentId)+"("+includesubDes+")";
					String subcompanyid = dci.getSubcompanyid1("" + departmentId);
					String subcompanyname = scci.getSubcompanyname(subcompanyid);
					if(StringUtils.isNotBlank(subcompanyname)){
						shareRealName += "["+subcompanyname+"]" ;
					}

					if ("".equals(shareRealName))
						continue;
					if(!isMobile){
						shareRealName = ds.getDepartmentLink(departmentId + "",shareRealName);
					}

					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;
				case 4: // 角色成员
					int roleId = rs.getInt("roleId");
					int rolelevel = rs.getInt("rolelevel");
					String roleLevelName = "";
					switch (rolelevel) {
					case 0:
						roleLevelName = SystemEnv.getHtmlLabelName(18939,
								userLanguage);
						break;
					case 1:
						roleLevelName = SystemEnv.getHtmlLabelName(141,
								userLanguage);
						break;
					case 2:
						roleLevelName = SystemEnv.getHtmlLabelName(140,
								userLanguage);
						break;
					}

					shareName = SystemEnv.getHtmlLabelName(18936, userLanguage);
					shareRealName = rci.getRolesRemark("" + roleId)+"/"+roleLevelName;
					if ("".equals(shareRealName))
						continue;					
					
					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;
				case 6: // 群组
					int orgGroupId = rs.getInt("orgGroupId");
					shareName = SystemEnv.getHtmlLabelName(24002, userLanguage);
					shareRealName = hogci.getOrgGroupName("" + orgGroupId);
					if ("".equals(shareRealName))
						continue;					
					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;
				case 5: // 所有人
					shareName = SystemEnv.getHtmlLabelName(1340, userLanguage);
					shareRealName = "";
					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;
				case 9: // 具体客户
					shareName = SystemEnv.getHtmlLabelName(18935, userLanguage);
					shareRealName = cici.getCustomerInfoname("" + shareCrmId);
					if ("".equals(shareRealName))
						continue;
					break;
				case 10: // 与创建人无关的岗位
					shareName =  SystemEnv.getHtmlLabelName(6086,userLanguage);					
    		        shareRealName = jbcom.getJobTitlesname(jobids)+"/";
				  if ("".equals(jbcom.getJobTitlesname(jobids))){
						continue;
					}
			      if(joblevel.equals("1")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(140,userLanguage);
	 			  } 			
	 			  if(joblevel.equals("2")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(19437,userLanguage)+"("+ds.getCompanyLink(jobsubcompany,scci.getSubCompanyname(jobsubcompany))+")";
	 			  }			
	 			  if(joblevel.equals("3")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(19438,userLanguage)+"("+ds.getDepartmentLink(jobdepartment ,dci.getDepartmentname(jobdepartment))+")";
	 			  }
				    	
				  if ("".equals(shareRealName))
						continue;
					shareRealLevel ="";
					break;	
				

				}
				if (shareLevel == 1)
					shareRealType = SystemEnv.getHtmlLabelName(367,
							userLanguage);
				else if (shareLevel == 2)
					shareRealType = SystemEnv.getHtmlLabelName(93,
							userLanguage);
				else if (shareLevel == 3)
					shareRealType = SystemEnv.getHtmlLabelName(17874,
							userLanguage);
				
				/** td12005 start */
				String downloadlevelName = "";
				if(shareLevel==1){
				downloadlevelName = downloadlevel == 1 ? SystemEnv.getHtmlLabelName(23733, userLanguage) :SystemEnv.getHtmlLabelName(23734, userLanguage);
				}
				/** td12005 end */
				if(isMobile){
					shareRealName = WaterMarkUtil.delHTMLTag(shareRealName);
				}
				Map<String,String> ht=new HashMap<String,String>();
				ht.put("shareId", ""+shareId);
				ht.put("shareName", shareName);
				ht.put("shareRealLevel", shareRealLevel);
				ht.put("shareRealName", shareRealName);
				ht.put("shareRealType", shareRealType);
				/** td12005 start */
				ht.put("downloadlevelName", downloadlevelName);
				ht.put("downloadlevel", ""+downloadlevel);
				/** td12005 end */
				
				ht.put("type",SystemEnv.getHtmlLabelName(15059, userLanguage));
				
				
				
				if ("true".equalsIgnoreCase(needCheckbox))
					ht.put("chk", ""+isDisabled);
				
				returnList.add(ht);
			}
		} else if (stringType == 3) { // 与客户相关的默认共享
			sqlStr = "select * from docshare where docid=? "
					+ " and sharetype<0 and sharetype>-80 and isSecDefaultShare='1' order by  issecdefaultshare desc,sharetype";
			rs.executeQuery(sqlStr,docId);
			while (rs.next()) {
                int seclevelmax = Util.getIntValue(rs.getString("seclevelmax"),255);
				String operategrouppar = userLanguage+"+3+0+"+hasVirtualCom;

				String shareName = "";
				String shareRealName = "";
				String shareRealLevel = "";
				String shareRealType = "";
				String isDisabled = "";

				int shareId = rs.getInt("id");
				int shareType = rs.getInt("sharetype");
				int shareLevel = rs.getInt("sharelevel");
				int downloadlevel = Util.getIntValue(rs.getString("downloadlevel"), 0);//TD12005
				
				String secLevel = Util.null2String(rs.getString("seclevel"));
				String isSecDefaultShare = Util.null2String(rs.getString("isSecDefaultShare"));
				if (!"1".equals(isAllowModiMShare)
						&& "1".equals(isSecDefaultShare)) {
					isDisabled = " disabled ";
				}

				String crmtype = "" + ((-1) * shareType);
				shareName = knotm.getShareTypeNew("8",operategrouppar);
			
                shareRealName = ctci.getCustomerTypename(crmtype);
				shareRealLevel =secLevel+"-"+seclevelmax ;
				if (shareLevel == 1)
					shareRealType = SystemEnv.getHtmlLabelName(367,
							userLanguage);
				else if (shareLevel == 2)
					shareRealType = SystemEnv.getHtmlLabelName(93,
							userLanguage);
				else if (shareLevel == 3)
					shareRealType = SystemEnv.getHtmlLabelName(17874,
							userLanguage);
				
				/** td12005 start */
				String downloadlevelName = "";
				if(shareLevel==1){
				downloadlevelName = downloadlevel == 1 ? SystemEnv.getHtmlLabelName(23733, userLanguage) :SystemEnv.getHtmlLabelName(23734, userLanguage);
				}
				/** td12005 end */
				
				Map<String,String> ht=new HashMap<String,String>();
				ht.put("shareId", ""+shareId);
				ht.put("shareName", shareName);
				ht.put("shareRealLevel", shareRealLevel);
				ht.put("shareRealName", shareRealName);
				ht.put("shareRealType", shareRealType);
				/** td12005 start */
				ht.put("downloadlevelName", downloadlevelName);
				ht.put("downloadlevel", ""+downloadlevel);
				/** td12005 end */
				
				ht.put("type",SystemEnv.getHtmlLabelName(15059, userLanguage));
				
				
				
				if ("true".equalsIgnoreCase(needCheckbox))
					ht.put("chk", ""+isDisabled);
				
				returnList.add(ht);
			}
		} else if (stringType == 4) { // 与创建人相关的默认共享(外部用户创建)
			sqlStr = "select * from docshare where docid=? "
					+ " and sharetype between -82 and -80 and isSecDefaultShare='1' order by  issecdefaultshare desc,sharetype";
			rs.executeQuery(sqlStr,docId);
			while (rs.next()) {
				String shareName = "";
				String shareRealName = "";
				String shareRealLevel = "";
				String shareRealType = "";
				String isDisabled = "";

				int shareId = rs.getInt("id");
				int shareType = rs.getInt("sharetype");
				int shareUserId = rs.getInt("userid");
				int shareLevel = rs.getInt("sharelevel");
				int downloadlevel = Util.getIntValue(rs.getString("downloadlevel"), 0);//TD12005
				
				String isSecDefaultShare = Util.null2String(rs.getString("isSecDefaultShare"));
				if (!"1".equals(isAllowModiMShare)
						&& "1".equals(isSecDefaultShare)) {
					isDisabled = " disabled ";
				}
				switch (shareType) {
				case -80: // 与创建人本人相关
					shareName = SystemEnv.getHtmlLabelName(15079, userLanguage);
					shareRealName = cici.getCustomerInfoname("" + shareUserId);
					if ("".equals(shareRealName))
						continue;					
					shareRealLevel = "";
					break;
				case -81: // 与创建人经理相关
					shareName = SystemEnv.getHtmlLabelName(15080, userLanguage);
					shareRealName = rcc.getLastname(cici.getCustomerInfomanager("" + shareUserId));
					if ("".equals(shareRealName))
						continue;
					if (!isMobile){
						shareRealName = ds.getHrmCard(cici.getCustomerInfomanager("" + shareUserId));
					}
					shareRealLevel = "";
					break;

				}
				if (shareLevel == 1)
					shareRealType = SystemEnv.getHtmlLabelName(367,
							userLanguage);
				else if (shareLevel == 2)
					shareRealType = SystemEnv.getHtmlLabelName(93,
							userLanguage);
				else if (shareLevel == 3)
					shareRealType = SystemEnv.getHtmlLabelName(17874,
							userLanguage);
				/** td12005 start */
				String downloadlevelName = "";
				if(shareLevel==1){
				downloadlevelName = downloadlevel == 1 ? SystemEnv.getHtmlLabelName(23733, userLanguage) :SystemEnv.getHtmlLabelName(23734, userLanguage);
				}
				/** td12005 end */
				
				Map<String,String> ht=new HashMap<String,String>();
				ht.put("shareId", ""+shareId);
				ht.put("shareName", shareName);
				ht.put("shareRealLevel", shareRealLevel);
				ht.put("shareRealName", shareRealName);
				ht.put("shareRealType", shareRealType);
				/** td12005 start */
				ht.put("downloadlevelName", downloadlevelName);
				ht.put("downloadlevel", ""+downloadlevel);
				/** td12005 end */
				ht.put("type",SystemEnv.getHtmlLabelName(15059, userLanguage));
				
				
				
				if ("true".equalsIgnoreCase(needCheckbox))
					ht.put("chk", ""+isDisabled);
				
				returnList.add(ht);
			}
		} else if (stringType == 5) { // 非默认共享
			sqlStr = "select * from docshare where docid=? "
					+ " and (isSecDefaultShare !='1'  or isSecDefaultShare is null) and sharetype!=89 order by  issecdefaultshare desc,sharetype";
			rs.executeQuery(sqlStr,docId);
			while (rs.next()) {
                int orgid = Util.getIntValue(rs.getString("orgid"),0);
				int seclevelmax = Util.getIntValue(rs.getString("seclevelmax"),255);
				
				int includesub = Util.getIntValue(rs.getString("includesub"),0);

				String joblevel=Util.null2String(rs.getString("joblevel"));
				String jobdepartment=Util.null2String(rs.getString("jobdepartment"));
				String jobsubcompany=Util.null2String(rs.getString("jobsubcompany"));
				String jobids=Util.null2String(rs.getString("jobids"));

				String allmanagers=Util.null2String(rs.getString("allmanagers"));
				String includesubDes=SystemEnv.getHtmlLabelName(10000010,userLanguage);
		        if(includesub==1){
			        includesubDes=SystemEnv.getHtmlLabelName(125963,userLanguage);
			     }

				String operategrouppar = userLanguage+"+1+"+orgid+"+"+hasVirtualCom;

				String shareName = "";
				String shareRealName = "";
				String shareRealLevel = "";
				String shareRealType = "";
				String isDisabled = "";

				int shareId = rs.getInt("id");
				int shareType = rs.getInt("sharetype");
				int shareUserId = rs.getInt("userid");
				int shareCrmId = rs.getInt("crmid");
				int shareLevel = rs.getInt("sharelevel");
				int downloadlevel = Util.getIntValue(rs.getString("downloadlevel"), 0);//TD12005
				String secLevel = Util.null2String(rs.getString("seclevel"));

				if (!"1".equals(isAllowModiNMShare)) {
					isDisabled = " disabled ";
				}
				switch (shareType) {
				case 1: // 人力资源
					shareName = SystemEnv.getHtmlLabelName(179, userLanguage);
					shareRealName = rcc.getLastname("" + shareUserId);
					if ("".equals(shareRealName))
						continue;
					if (!isMobile){
						shareRealName = ds.getHrmCard(shareUserId + "");
					}
					break;
				case 2: // 分部
					int subcompanyId = rs.getInt("subcompanyid");
					shareName = SystemEnv.getHtmlLabelName(141, userLanguage);
					shareRealName = scci.getSubCompanyname("" + subcompanyId)+"("+includesubDes+")";
					if ("".equals(shareRealName))
						continue;
					if (!isMobile){
						shareRealName = ds.getCompanyLink(subcompanyId + "",shareRealName);
					}
					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;
				case 3: // 部门
					int departmentId = rs.getInt("departmentid");
					shareName = SystemEnv.getHtmlLabelName(18939, userLanguage);
					shareRealName = dci.getDepartmentname("" + departmentId)+"("+includesubDes+")";

					String subcompanyid = dci.getSubcompanyid1("" + departmentId);
					String subcompanyname = scci.getSubcompanyname(subcompanyid);
					if(StringUtils.isNotBlank(subcompanyname)){
						shareRealName += "["+subcompanyname+"]" ;
					}

					if ("".equals(shareRealName))
						continue;
					if (!isMobile){
						shareRealName = ds.getDepartmentLink(departmentId + "",shareRealName);
					}

					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;
				case 4: // 角色成员
					int roleId = rs.getInt("roleId");
					shareName = SystemEnv.getHtmlLabelName(18936, userLanguage);
					int rolelevel = rs.getInt("rolelevel");
					String roleLevelName = "";
					switch (rolelevel) {
					case 0:
						roleLevelName = SystemEnv.getHtmlLabelName(18939,
								userLanguage);
						break;
					case 1:
						roleLevelName = SystemEnv.getHtmlLabelName(141,
								userLanguage);
						break;
					case 2:
						roleLevelName = SystemEnv.getHtmlLabelName(140,
								userLanguage);
						break;
					}
					shareRealName = rci.getRolesRemark("" + roleId)+"/"+roleLevelName;
					if ("".equals(shareRealName))
						continue;					
						shareRealLevel =secLevel+"-"+seclevelmax ;
					break;
				case 5: // 所有人
					shareName = SystemEnv.getHtmlLabelName(1340, userLanguage);
					shareRealName = "";			
					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;
				case 6: // 群组
					int orgGroupId = rs.getInt("orgGroupId");
					shareName = SystemEnv.getHtmlLabelName(24002, userLanguage);
					shareRealName = hogci.getOrgGroupName("" + orgGroupId);
					if ("".equals(shareRealName))
						continue;					
					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;

				case 10: // 与创建人无关的岗位
					shareName =  SystemEnv.getHtmlLabelName(6086,userLanguage);					
    		        shareRealName = jbcom.getJobTitlesname(jobids)+"/";
				  if ("".equals(jbcom.getJobTitlesname(jobids))){
						continue;
					}
			      if(joblevel.equals("1")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(140,userLanguage);
	 			  } 			
	 			  if(joblevel.equals("2")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(19437,userLanguage)+"("+ds.getCompanyLink(jobsubcompany,null)+")";
	 			  }			
	 			  if(joblevel.equals("3")){
	 				shareRealName = shareRealName + SystemEnv.getHtmlLabelName(19438,userLanguage)+"("+ds.getDepartmentLink(jobdepartment,null)+")";
	 			  }
				    	
				  if ("".equals(shareRealName))
						continue;
					shareRealLevel ="";
					break;	
				 

				case -80: // 与创建人本人相关
					shareName = SystemEnv.getHtmlLabelName(15079, userLanguage);
					shareRealName = cici.getCustomerInfoname("" + shareUserId);
					if ("".equals(shareRealName))
						continue;					
					shareRealLevel = "";
					break;
				case 80: // 与创建人本人相关
					shareName = knotm.getShareTypeNew("1",operategrouppar);
					shareRealName = rcc.getLastname("" + shareUserId);
					if ("".equals(shareRealName))
						continue;
					if (!isMobile){
						shareRealName = ds.getHrmCard(shareUserId + "");
					}

					shareRealLevel = "";
					break;
				case 81: // 与创建人直接上级相关
				if(orgid==0){
				if(allmanagers.equals("1")){
				    shareName =  knotm.getShareTypeNew("3",operategrouppar);
                    shareRealName=rcc.getMulResourcename2(rcc.getManagersIDs(""+shareUserId));					
					if ("".equals(rcc.getManagersIDs(""+shareUserId)+"")||"0".equals(rcc.getManagersIDs(""+shareUserId)+""))
						continue;
					if(isMobile){
						shareRealName = ds.getHrmCard(rcc.getManagersIDs(""+shareUserId),isMobile);
					}
				}else{
					shareName =  knotm.getShareTypeNew("2",operategrouppar);
					shareRealName = rcc.getLastname(rcc.getManagerID(""+ shareUserId));
					if ("".equals(shareRealName))
						continue;
					if(isMobile){
						shareRealName = ds.getHrmCard(rcc.getManagerID(""+ shareUserId),isMobile);
					}
				   }	
			   }else if(orgid<0){
				   String allmtem="";
					if(allmanagers.equals("1")){
						shareName =  knotm.getShareTypeNew("3",operategrouppar);
						 rs2.executeQuery("select * from HrmResourceVirtual where virtualtype=? and resourceid=?",orgid,shareUserId);
						 if(rs2.next()){
							 allmtem=rs2.getString("managerstr");
							 shareRealName = ds.getHrmCard(allmtem);
							 if (isMobile){
								 shareRealName = ds.getHrmCard(allmtem,isMobile);
							 }
						}
					}else{
						 shareName =  knotm.getShareTypeNew("2",operategrouppar);
						 rs2.executeQuery("select * from HrmResourceVirtual where virtualtype=? and resourceid=",orgid,shareUserId);
						 if(rs2.next()){
							 allmtem=rs2.getString("managerid");
							 shareRealName = ds.getHrmCard(allmtem);
							 if (isMobile){
								 shareRealName = ds.getHrmCard(allmtem,isMobile);
							 }
						 }
					 }


					if ("".equals(allmtem))
						continue;
					
			      }	
				   if ("".equals(shareRealName))
						continue;

					shareRealLevel = "";

					break;

				case 84: // 与创建人分部相关

                    shareName =  knotm.getShareTypeNew("4",operategrouppar);
					departmentId =Util.getIntValue(rcc.getDepartmentID("" + shareUserId));
					String subCompanyName = scci.getSubCompanyname(dci.getSubcompanyid1(departmentId+""));
					if(orgid==0){
						shareRealName = subCompanyName;
						if ("".equals(shareRealName))
							continue;
						if (!isMobile){
							//shareRealName += "("+includesubDes+")";
							shareRealName = ds.getCompanyLink(dci.getSubcompanyid1(departmentId+""),shareRealName);
						}

					}else if(orgid<0){
					
						 rs2.executeQuery("select * from HrmResourceVirtual where virtualtype=? and resourceid=?",orgid,shareUserId);
						 if(rs2.next()){
							 shareRealName = scci.getSubCompanyname(rs2.getString("subcompanyid"));
							 if ("".equals(shareRealName))
								continue;
							 if (!isMobile){
								 //shareRealName += "("+includesubDes+")";
								 shareRealName = ds.getCompanyLink(rs2.getString("subcompanyid"),shareRealName);
							 }

						}
					 
					
					}
					  if ("".equals(shareRealName))
						continue;
					shareRealLevel =secLevel+"-"+seclevelmax ;
					break;

					
				case 85: // 与创建人部门相关


				    shareName =  knotm.getShareTypeNew("5",operategrouppar);
					departmentId =  Util.getIntValue(rcc.getDepartmentID(""
							+ shareUserId));
					String departmentName = dci.getDepartmentname(departmentId+"");
					subcompanyid = rcc.getSubCompanyID("" + shareUserId);
					subcompanyname = scci.getSubcompanyname(subcompanyid);

					if(orgid==0){
						shareRealName = departmentName+"["+subcompanyname+"]";
						if ("".equals(departmentName))
							continue;
						if(!isMobile){
							//shareRealName += "("+includesubDes+")";
							shareRealName = ds.getDepartmentLink(departmentId + "",shareRealName);
						}

					}else if(orgid<0){
						
						 rs2.executeQuery("select * from HrmResourceVirtual where virtualtype=? and resourceid=?",orgid,shareUserId);
						 if(rs2.next()){
							 shareRealName = dci.getDepartmentname(rs2.getString("departmentid"));
							 if ("".equals(shareRealName))
								continue;
							 if(!isMobile){
								 //shareRealName += "("+includesubDes+")";
								 shareRealName = ds.getDepartmentLink(rs2.getString("departmentid"),shareRealName);
							 }

						 }
					 
					
					}
					  if ("".equals(shareRealName))
						continue;
					shareRealLevel = secLevel+"-"+seclevelmax ;
					break;


				case -81: // 与创建人经理相关
					shareName = SystemEnv.getHtmlLabelName(15080, userLanguage);
					shareRealName = rcc.getLastname(rcc.getManagerID(""+ shareUserId));
					if ("".equals(shareRealName))
						continue;
					if (!isMobile){
						shareRealName = ds.getHrmCard(rcc.getManagerID(""+ shareUserId));
					}
					shareRealLevel = "";
					break;
				case 9: // 具体客户
					shareName = SystemEnv.getHtmlLabelName(18935, userLanguage);
					shareRealName = cici.getCustomerInfoname("" + shareCrmId);
					if ("".equals(shareRealName))
						continue;
					// shareRealLevel=createrName+"的经理的所有上级";
					break;
				default: // 客户
					String crmtype = "" + ((-1) * shareType);
					shareName = SystemEnv.getHtmlLabelName(1282, userLanguage);
					shareRealLevel =secLevel+"-"+seclevelmax ;
					shareRealName = ctci.getCustomerTypename(crmtype);
					if ("".equals(shareRealName))
						continue;					

				}
				if (shareLevel == 1)
					shareRealType = SystemEnv.getHtmlLabelName(367,userLanguage);
				else if (shareLevel == 2)
					shareRealType = SystemEnv.getHtmlLabelName(93,userLanguage);
				else if (shareLevel == 3)
					shareRealType = SystemEnv.getHtmlLabelName(17874,userLanguage);

				/** td12005 start */
				String downloadlevelName = "";
				if(shareLevel==1){
				downloadlevelName = downloadlevel == 1 ? SystemEnv.getHtmlLabelName(23733, userLanguage) :SystemEnv.getHtmlLabelName(23734, userLanguage);
				}
				/** td12005 end */
				
				Map<String,String> ht=new HashMap<String,String>();
				
				ht.put("shareLevel",shareLevel+"");
				ht.put("shareType",shareType+"");
				ht.put("shareUserId",shareUserId+"");
				
				ht.put("shareId", ""+shareId);
				ht.put("shareName", shareName);
				ht.put("shareRealLevel", shareRealLevel);
				ht.put("shareRealName", shareRealName);
				ht.put("shareRealType", shareRealType);
				/** td12005 start */
				ht.put("downloadlevelName", downloadlevelName);
				ht.put("downloadlevel", ""+downloadlevel);
				/** td12005 end */
				
				ht.put("type",SystemEnv.getHtmlLabelName(18574, userLanguage));
				
				if ("true".equalsIgnoreCase(needCheckbox))
					ht.put("chk", ""+isDisabled);
				
				returnList.add(ht);
			}
			
			//所有上级权限 展现 89
			sqlStr = "select * from docshare where docid=? and (isSecDefaultShare!='1' or isSecDefaultShare is null) and  sharetype=89 order by  issecdefaultshare desc,sharetype";
			rs.executeQuery(sqlStr, docId);
			int count = rs.getCounts();
			int i =0 ;
			String shareRealName = "";
			while (rs.next()) {
				i ++;
				String shareName = "";
				String shareRealLevel = "";
				String shareRealType = "";
				String isDisabled = "";
				int shareUserId = rs.getInt("userid");
				shareRealName += rcc.getLastname(""+ shareUserId);
				if ("".equals(shareRealName))
					continue;

				if(i<count){
					shareRealName+="，";
					continue;
				}
				int shareId = rs.getInt("id");
				
				int shareLevel = rs.getInt("sharelevel");
				int downloadlevel = Util.getIntValue(rs.getString("downloadlevel"), 0);//TD12005
				String isSecDefaultShare = Util.null2String(rs
						.getString("isSecDefaultShare"));
				if (!"1".equals(isAllowModiMShare)
						&& "1".equals(isSecDefaultShare)) {
					isDisabled = " disabled ";
				}
				shareName = SystemEnv.getHtmlLabelName(385205,userLanguage);
				RecordSet urs = new RecordSet();
				urs.execute("select doccreaterid from DocDetail where id="+docId);
				if(urs.next()){
					shareRealLevel = rcc.getLastname(urs.getString(1)) + SystemEnv.getHtmlLabelName(10000011,userLanguage);
				}
				if (shareLevel == 1)
					shareRealType = SystemEnv.getHtmlLabelName(367,userLanguage);
				else if (shareLevel == 2)
					shareRealType = SystemEnv.getHtmlLabelName(93,userLanguage);
				else if (shareLevel == 3)
					shareRealType = SystemEnv.getHtmlLabelName(17874,userLanguage);
				
				Map<String,String> ht=new HashMap<String,String>();
				ht.put("shareId", ""+shareId);
				ht.put("shareName", shareName);
				ht.put("shareRealLevel", shareRealLevel);
				ht.put("shareRealName", shareRealName);
				ht.put("shareRealType", shareRealType);
				/** td12005 start */
				String downloadlevelName = "";
				if(shareLevel==1){
					downloadlevelName = downloadlevel == 1 ? SystemEnv.getHtmlLabelName(23733, userLanguage) :SystemEnv.getHtmlLabelName(23734, userLanguage);
				}
				ht.put("downloadlevelName", downloadlevelName);
				ht.put("downloadlevel", ""+downloadlevel);
				/** td12005 end */
				ht.put("type",SystemEnv.getHtmlLabelName(18574, userLanguage));
				if ("true".equalsIgnoreCase(needCheckbox))
					ht.put("chk", ""+isDisabled);
				returnList.add(ht);
			}
		}

		return returnList;
	}
	/**
	 * 移动端系统文档权限列表
	 * @params user
	 * @params docid
	 * @params params 自定义参数集
	 * @author sunch
	 * */
	public Map<String, Object> getMobileShareList(User user, int docid) {
		Map<String,Object> apidatas = new HashMap<String,Object>();
		SecCategoryComInfo scci = new SecCategoryComInfo();
		String secId= "";
		RecordSet rs = new RecordSet();
		rs.executeQuery("select seccategory from docdetail where id=" + docid);
		if(rs.next()){
			secId=rs.getString("seccategory");
		}
		boolean nodownload = scci.getNoDownload(secId).equals("1");//得到此分录下的文档最大可上传附件大小
		apidatas = getDocShare(user,docid,true);
		apidatas.put("nodownload",nodownload);
		return  apidatas;

	}
	/**
	 * 移动端系统文档权限列表
	 * @params user
	 * @params docid
	 * @params
	 * @author sunch
	 * */
	private Map<String,Object>  getDocShare(User user, int docid) {
		return getDocShare(user,docid,false);
	}
	private Map<String,Object>  getDocShare(User user, int docid, boolean isMobile) {
		Map<String,Object> apidatas = new HashMap<String,Object>();
		ArrayList<Map<String,String>> dataList1=new ArrayList<Map<String,String>>();
		ArrayList<Map<String,String>> dataList2=new ArrayList<Map<String,String>>();
		try{
			dataList1.addAll(getShareList(1,docid,"true",user.getLanguage(),isMobile));//与创建人相关的默认共享 (内部)
			dataList1.addAll(getShareList(2,docid,"true",user.getLanguage(),isMobile));//与创建人本人无关的默认共享
			dataList1.addAll(getShareList(3,docid,"true",user.getLanguage(),isMobile));//与客户相关的默认共享
			dataList1.addAll(getShareList(4,docid,"true",user.getLanguage(),isMobile));//创建人相关的默认共享(外部用户创建)
			dataList2.addAll(getShareList(5,docid,"true",user.getLanguage(),isMobile));//非默认共享
            apidatas.put("defaultShareList",dataList1);//默认共享
            apidatas.put("nonDefaultShareList",dataList2);//非默认共享
		}catch(Exception e){

		}
		return apidatas;
	}
	/**
	 * 更新文档共享
	 * @param userids 要更新的人员的id，多个id之间用逗号隔开
	 * @param docids  要更新的文档id，多个id之间用逗号隔开
	 * @param sharelevel 权限（1-查看；2-编辑，3-完全控制）
	 * @param download 是否可下载
	 */
	public void updateShareForUser(String userids,String docids,int sharelevel,boolean download){
		RecordSet rs = new RecordSet();
		if(userids.isEmpty() || docids.isEmpty()) {
			rs.writeLog("DocShareService updateShareForUser userids:"+userids+"--docids:"+docids);
			return;
		}
		String sql = "update docshare set sharelevel="+sharelevel+",downloadlevel="+(download?1:0)+
				" where sharetype in (1,80,81,86) and docid in("+docids+") and userid in("+userids+")";
		rs.execute(sql);
		//更新shareinnerdoc表
		for(String docid : docids.split(",")){
			try{
				DocViewer dv = new DocViewer();
				dv.setDocShareByDoc(docid + "");
			}catch(Exception e){
				rs.writeLog("DocShareService updateShareForUser userids:"+userids+"--docids:"+docids+"--docid:"+docid
						+"--e:"+e.getMessage());
			}
		}
	}
}
