本帖最后由 inxxin 于 2014-5-12 13:13 编辑
问题场景: “OA/信息发布管理/新闻管理/新闻查看”源代码中有统计“有权限阅读本知识的人员数量功能”,其中代码2.2部分有点疑惑不知道是否正确,请专家指导,谢谢!
源代码位置:/BIZ/OA/knowledge/logic/action/knowledgeCustom.action.m
action名称:getNoReaderCountAction中的getCanReaders(...)方法
代码设计思路:
1、先过滤出有阅读本知识权限的组织信息,并分类保存到psnIDs和orgIDs中; String orgIDs = "'-'", psnIDs = "'-'"; String sqlGetRights = "select r.fOrgID, r.fOrgKind from OA_KM_Rights r where r.fKWID ='"+KWID+"' and r.fCanReadKW = 1 "; Table table = KSQL.select(sqlGetRights, null, OADataModel, null); Iterator<Row> rows = table.iterator(); while (rows.hasNext()) { Row rsRights = rows.next(); if (!(rsRights.getString("fOrgKind").equalsIgnoreCase("psn"))) { orgIDs += ",'"+rsRights.getString("fOrgID")+"'"; } if (rsRights.getString("fOrgKind").equalsIgnoreCase("psn")) { psnIDs += ",'"+rsRights.getString("fOrgID")+"'"; } }
2、统计人员 2.1 对于psnIDs中的人员直接到SA-OPPerson中统计即可; "Select distinct p as sID, p.sName,mainOrg.sFName from SA_OPPerson p join SA_OPOrg mainOrg on p.sMainOrgID = mainOrg where p in ("+psnIDs+") "
2.2 对于orgIDs中的存在的人员信息,必须遍历出每个组织下可能存在的人员; "Select distinct p as sID, p.sName,mainOrg.sFName from SA_OPPerson p join SA_OPOrg mainOrg on p.sMainOrgID = mainOrg where p in ( select pm.sPersonID from SA_OPOrg org join SA_OPOrg orgC on orgC.sFID like concat(org.sFID , '%') join SA_OPOrg pm on orgC = pm.sParent where org in ("+orgIDs+") ) orderby mainOrg.sFName, p.sName ";
提出问题?
在2.2中join SA_OPOrg orgC on orgC.sFIDlike concat(org.sFID , '%')就能够将本组织中子孙组织的信息都连接到,那为什么还需要再次连接SA_OPOrg pm,这样不就重复了吗?是否join一次就可以?
|