@Override public void init() { while (true) { try { String total = headerSql .executeQueryForUnique( "select count(1) as total from t_register_work where isfinsh='等待'") .get("total"); if (!"0".equals(total)) { List<Map<String, String>> t_register_work = headerSql.executeQuery( "select * from t_register_work where worktime<='" + Util.YMDHMS.format(new Date()) + "' and isfinsh='等待' order by worktime limit 0,1"); if (t_register_work.size() > 0) { appPhonePojo = new AppPhonePojo( "SELECT a.t_registerid,t_app.*,t_phone.* from t_app, t_phone, (SELECT t_register.* from t_register WHERE t_registerid='" + t_register_work.get(0).get("t_registerid") + "')a WHERE t_app.t_appid=a.t_appid and t_phone.t_phoneid=a.t_phoneid"); regist(t_register_work); } else { Log.log.info("目前没有任务(Register)."); } } int t = new Random().nextInt(5); Log.log.info("Sleep " + t + " minutes."); Thread.sleep(t * 1000 * 60); } catch (Exception e) { Log.log.info(Log.printTrace(e)); } } }
private void regist(List<Map<String, String>> t_register_work) throws Exception { String context = connect(); Log.log.info("connect --> " + context); context = ad(); Log.log.info("ad --> " + context); JSONArray adjJsonArray = JSONObject.fromObject(context).getJSONArray("List"); // 下载app if ("wifi".equals(appPhonePojo.getPhonePojo().getNet())) { String adId = adjJsonArray.getJSONObject(0).getString("Id"); String adPackage = adjJsonArray.getJSONObject(0).getString("AdPackage"); String downUrl = adjJsonArray.getJSONObject(0).getString("DownUrl"); headerSql.del_add_upd( "INSERT INTO t_download_apk(t_registerid,adid,package,addtime)VALUES(?,?,?,?)", new String[] { appPhonePojo.getRegisterid(), adId, adPackage, Util.YMDHMS.format(new Date()) }); new Thread( new Runnable() { @Override public void run() { try { download(downUrl); } catch (Exception e) { Log.log.info("下载app", e); } } }) .start(); } appPhonePojo.getPhonePojo().setAdid(adjJsonArray.getJSONObject(0).getString("Id")); context = show(); for (int i = 0; i < adjJsonArray.size(); i++) { String sImage = adjJsonArray.getJSONObject(i).getString("Image"); get(sImage); } headerSql.del_add_upd( "update t_register_work set finshtime = '" + Util.YMDHMS.format(new Date()) + "',isfinsh = '完成' where t_register_workid='" + t_register_work.get(0).get("t_register_workid") + "'"); }