|
楼主 |
发表于 2021-4-9 14:44:16
|
显示全部楼层
本帖最后由 akshay 于 2021-4-9 15:05 编辑
//定义两个判断用的参数
public static String orgVersion = "";
public static Map<String, Set<String>> orgs = new ConcurrentHashMap<String, Set<String>>();
private static String getOrgVersionFromDB(){
String result = null;
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try{
con = DBUtils.getConnection();
String sql = "select sCode as sCode from SA_Code where sType='orgVersion'";
stmt = con.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
result = rs.getString("sCode");
break;
}
}catch(Exception e){
logger.error(e.getMessage()+"", e);
}finally{
if (rs != null){
try{
rs.close();
}catch(SQLException e){};
}
if (stmt != null){
try{
stmt.close();
}catch(SQLException e){};
}
if (con != null){
try {
con.close();
} catch (SQLException e) {}
}
}
return result;
}//读取企业微信的组织机构是否被修改了,如果修改了就对orgVersion重新赋值
private synchronized static Map<String, Set<String>> getAllPerson(){
String orgVersionFromDB = getOrgVersionFromDB();
if (orgVersionFromDB.equals(orgVersion)){
return orgs;
}else{
orgs = loadOrgsFromDB();
orgVersion = orgVersionFromDB;
return orgs;
}
}
private static Map<String, Set<String>> loadOrgsFromDB(){
Map<String, Set<String>> result = new HashMap<String, Set<String>>();
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try{
con = DBUtils.getConnection();
String sql = "select sFID as sFID, sPersonID as sPersonID from SA_OPOrg where sValidState>0 and sOrgKindID='psm'";
stmt = con.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
String fid = rs.getString("sFID");
String id = rs.getString("sPersonID");
Set<String> fids = result.get(id);
if (fids == null){
fids = new HashSet<String>();
result.put(id, fids);
}
fids.add(fid);
}
}catch(Exception e){
logger.error(e.getMessage()+"", e);
}finally{
if (rs != null){
try{
rs.close();
}catch(SQLException e){};
}
if (stmt != null){
try{
stmt.close();
}catch(SQLException e){};
}
if (con != null){
try {
con.close();
} catch (SQLException e) {}
}
}
return result;
}
|
|