}
public static String getJson(String daystart,boolean extamsg) throws JSONException, SQLException
{
JSONObject jsonObj = new JSONObject();
jsonObj.put("code", "1");
MySqlConn m_fpsql = getConn();
String strSql = "select userid,email,cname,role,permission,'-' as queryday,opuser,optime from users_json order by role desc,userid";
if(daystart!=null&&!daystart.isEmpty())
{
strSql = " select userid,email,cname,role,permission,opuser,optime from users_json where (cname not in (select nick from query_analyser.day_user_pv where queryday>'"+daystart+"')) order by role desc,userid";
}
if(extamsg)
{
strSql = " select a.userid as userid,a.email as email ,a.cname as cname,a.role as role,a.permission as permission,a.opuser as opuser,a.optime as optime, b.queryday as queryday " +
"from ( " +
""+strSql+") " +
" a " +
" left join (select nick,max(queryday) as queryday from query_analyser.day_user_pv group by nick ) b" +
" on a.cname=b.nick order by role desc,queryday desc" ;
}
jsonObj.put("_exehql", strSql);
Connection conn = m_fpsql.getConn();
Statement stmt = conn.createStatement();
try {
ResultSet res = stmt.executeQuery(strSql);
JSONArray userlist=new JSONArray();
while (res.next()) {
JSONObject item = new JSONObject();
item.put("userid", String.valueOf(res.getString("userid")));
item.put("email", String.valueOf(res.getString("email")));
item.put("queryday", String.valueOf(res.getString("queryday")));
item.put("cname", String.valueOf(res.getString("cname")));
item.put("role", Integer.parseInt(res.getString("role")));
item.put("permission", new JSONArray(res.getString("permission")));
item.put("opuser", String.valueOf(res.getString("opuser")));
item.put("optime", String.valueOf(res.getString("optime")));
userlist.put(item);
}
m_fpsql.close();
jsonObj.put("code", "1");
jsonObj.put("message", "success");
JSONObject dddd = new JSONObject();
dddd.put("users", userlist);
jsonObj.put("data", dddd);
} catch (Exception e) {
jsonObj.put("message", e.toString());
jsonObj.put("code", "0");
}finally{
m_fpsql.close();
}
return jsonObj.toString();
}