SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
Map stormconf = Utils.readStormConfig();
String connstr = (String) stormconf.get("higo.download.offline.conn");
String uname = (String) stormconf.get("higo.download.offline.username");
String passwd = (String) stormconf.get("higo.download.offline.passwd");
MySqlConn m_fpsql = new MySqlConn(connstr, uname, passwd);
Connection conn = m_fpsql.getConn();
Statement stmt = conn.createStatement();
String strsqlJoin="select '1' as source " +
",tableShowName as tableShowName" +
",tableName as tableName" +
",colsShowName as colsShowName" +
",colsName as colsName" +
",colsType as colsType" +
",splitString as splitString" +
",txtStorePath as txtStorePath" +
",indexStorePath as indexStorePath" +
",'0' as extval" +
",'0' as isfinish" +
",status as status" +
",username as username" +
",createtime as createtime" +
",lastuptime as lastuptime" +
",joins as joins" +
",'2' as stage" +
",percent as percent" +
",resultkb as resultkb" +
",memo as memo" +
" from adhoc_joins where username='"+username.replaceAll("'", "")+"' and status<>'DEL' and (copy_uuid is null or copy_uuid='') "+joins+" ";
StringBuffer bufferSql=new StringBuffer();
if(type==0)//个人中心列表
{
String strsqlJoin2="select '3' as source " +
",tableShowName as tableShowName" +
",tableName as tableName" +
",colsShowName as colsShowName" +
",colsName as colsName" +
",colsType as colsType" +
",splitString as splitString" +
",txtStorePath as txtStorePath" +
",indexStorePath as indexStorePath" +
",'0' as extval" +
",'0' as isfinish" +
",status as status" +
",username as username" +
",createtime as createtime" +
",lastuptime as lastuptime" +
",joins as joins" +
",'2' as stage" +
",percent as percent" +
",resultkb as resultkb" +
",memo as memo" +
" from adhoc_joins where username='"+username.replaceAll("'", "")+"' and status<>'DEL' and (copy_uuid is not null and copy_uuid<>'' and status='INDEX' ) "+joins+" ";
String strsqlDownload="select '2' as source " +
",jobname as tableShowName" +
",uuid as tableName" +
",cols as colsShowName" +
",'empty' as colsName" +
",'empty' as colsType" +
",'default' as splitString" +
",storedir as txtStorePath" +
",'empty' as indexStorePath" +
",extval as extval" +
",isfinish as isfinish" +
",'INDEX' as status" +
",username as username" +
",starttime as createtime" +
",endtime as lastuptime" +
",'' as joins" +
",stage as stage" +
",percent as percent" +
",resultkb as resultkb" +
",'' as memo" +
" from adhoc_download where username='"+username.replaceAll("'", "")+"' and status<>'DEL' and storedir not like '%abtest%' ";
String strsqlAbtest="select '8' as source " +
",jobname as tableShowName" +
",uuid as tableName" +
",cols as colsShowName" +
",'empty' as colsName" +
",'empty' as colsType" +
",'default' as splitString" +
",storedir as txtStorePath" +
",'empty' as indexStorePath" +
",extval as extval" +
",isfinish as isfinish" +
",'INDEX' as status" +
",username as username" +
",starttime as createtime" +
",endtime as lastuptime" +
",'' as joins" +
",stage as stage" +
",percent as percent" +
",resultkb as resultkb" +
",'' as memo" +
" from adhoc_download where username='"+username.replaceAll("'", "")+"' and status<>'DEL' and storedir like '%abtest%' ";
bufferSql.append("select source,tableShowName,tableName,colsShowName" +
",colsName,colsType,splitString,txtStorePath,indexStorePath,extval,status,username," +
"createtime,lastuptime,joins,stage,percent,resultkb,memo");
bufferSql.append(" from ("+strsqlJoin+" union "+strsqlDownload+" union "+strsqlJoin2+" union "+strsqlAbtest+") tmp order by tmp.createtime desc limit "+start+","+rows+" ");
}
if(type==1)//for join
{
bufferSql.append(strsqlJoin+" and status='INDEX' and resultkb<=512000 order by createtime desc limit "+start+","+rows+" ");
}
String sql=bufferSql.toString();
TableJoin.LOG.info("getUserTables:"+sql);
ResultSet res = stmt.executeQuery(sql);
JSONObject jsonObj = new JSONObject();
jsonObj.put("code", "1");
jsonObj.put("_exehql", sql);
JSONArray jsonArray = new JSONArray();
while (res.next()) {
JSONObject item = new JSONObject();
item.put("source", res.getString("source"));
item.put("tableShowName", res.getString("tableShowName"));//展示名称
item.put("tableName", res.getString("tableName"));//uuid
item.put("colsShowName", res.getString("colsShowName").replaceAll("\\(", "_").replaceAll("\\)", "_").replaceAll(" ", "").replaceAll("_,", ",").replaceAll(",$", ""));
item.put("colsName", res.getString("colsName"));
item.put("colsType", res.getString("colsType"));
item.put("splitString", res.getString("splitString"));
item.put("txtStorePath", res.getString("txtStorePath"));
item.put("indexStorePath", res.getString("indexStorePath"));
item.put("extval", res.getString("extval"));
item.put("status", res.getString("status"));
item.put("username", res.getString("username"));
item.put("createtime", res.getString("createtime"));
item.put("lastuptime", res.getString("lastuptime"));
item.put("joins", res.getString("joins"));
item.put("stage", res.getString("stage"));
item.put("percent", res.getString("percent"));
item.put("resultkb", parseInt(res.getString("resultkb"))>0?res.getString("resultkb"):"<1");
item.put("memo", String.valueOf(res.getString("memo")));
boolean isoversize= (!res.getString("source").equals("8"))&&parseInt(res.getString("resultkb"))>512000;
boolean issuccess=res.getString("status").equals("INDEX")&&res.getString("extval").equals("0");
boolean iserror=res.getString("status").equals("FAIL")||!res.getString("extval").equals("0");
double percent=parsePercent(res.getString("stage"),res.getString("percent"),issuccess);
if(percent>=100&&res.getString("source").equals("8")&&parseInt(res.getString("resultkb"))<=0)
{
issuccess=false;
iserror=true;
}
boolean isallowEdit=!res.getString("status").equals("INDEXING")&&res.getString("source").equals("1");
item.put("allowCreate",String.valueOf(res.getString("source").equals("2")&&issuccess&&percent>=100&&!isoversize));//是否允许将离线下载转换为个人表
item.put("allowUpload",String.valueOf(isallowEdit&&res.getString("status").equals("init")));//上传
item.put("allowDownload",String.valueOf((issuccess||res.getString("status").equals("DUMP"))&&percent>=100));//下载
item.put("allowJoin",String.valueOf(res.getString("source").equals("1")&&issuccess&&percent>=100&&!isoversize));//join
item.put("allowSend",String.valueOf(issuccess&&percent>=100));//推送
item.put("isError", iserror);
String uuidshow=iserror?("<br>"+res.getString("tableName")):"";
item.put("proccess", ((res.getString("status").equals("DUMP")||iserror)?"0":DF_FORMAT.format(percent))+"%");
item.put("msg", String.valueOf(iserror?"服务器异常":isoversize?"数据文件超过500M ":res.getString("status").equals("DUMP")?"设置关联关系的字段有重复值":issuccess&&percent>=100?"成功":res.getString("status").equals("init")?"等待上传数据":"处理中...")+uuidshow);
jsonArray.put(item);
}
HashMap<String,String> cnt=getUserTablesCount(username, type,moduleName);
JSONObject data = new JSONObject();
data.put("list",jsonArray);
data.put("total",cnt.get("cnt"));
jsonObj.put("data",data);
jsonObj.put("total_debug", new JSONObject(cnt));
m_fpsql.close();
if (callback != null && callback.length() > 0) {
return callback + "(" + jsonObj.toString() + ")";
} else {