|
@@ -32,21 +32,21 @@ public class DownloadTask implements ITask {
|
|
|
OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
|
|
|
|
|
|
Integer max = 2;
|
|
|
- List<Record> count = Db.use("local").find("select * from study where status =4");
|
|
|
+// List<Record> count = Db.use("local").find("select * from study where status =4");
|
|
|
//同时下载的队列
|
|
|
- Integer flag = count.size();
|
|
|
- if (flag >= max) {
|
|
|
- return;
|
|
|
- }
|
|
|
- List<Record> studyidfinds = Db.use("local").find("select * from study where status =1 or status =2 order by createAt asc limit 5");
|
|
|
+// Integer flag = count.size();
|
|
|
+// if (flag >= max) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+ List<Record> studyidfinds = Db.use("local").find("select * from study where status =1 or status =2 order by createAt asc limit 1");
|
|
|
if (studyidfinds == null) {
|
|
|
return;
|
|
|
}
|
|
|
for (Record studyidfind : studyidfinds) {
|
|
|
- flag++;
|
|
|
- if (flag > max) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+// flag++;
|
|
|
+// if (flag > max) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
//状态4:下载中
|
|
|
studyidfind.set("status", 4);
|
|
|
Db.use("local").update("study", studyidfind);
|
|
@@ -55,19 +55,16 @@ public class DownloadTask implements ITask {
|
|
|
Request request = new Request.Builder()
|
|
|
.url(record.getStr("URL"))
|
|
|
.build();
|
|
|
+ try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
|
|
|
+ if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
|
|
|
|
|
|
- OKHTTP_CLIENT.newCall(request).enqueue(new Callback() {
|
|
|
- @Override public void onFailure(Call call, IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ writeFile(response,studyidfind.getStr("studyuid"));
|
|
|
|
|
|
- @Override public void onResponse(Call call, Response response) throws IOException {
|
|
|
- try (ResponseBody responseBody = response.body()) {
|
|
|
- if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
|
|
|
- writeFile(response,studyidfind.getStr("studyuid"));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ } catch (IOException e1) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
studyidfind.set("status", 3);
|
|
|
Db.use("local").update("study", studyidfind);
|