@@ -1,14 +1,11 @@ |
||
1 | 1 |
package ai.pai.lensman.bean; |
2 | 2 |
|
3 |
-/** |
|
4 |
- * Created by chengzhenyu on 2016/8/27. |
|
5 |
- */ |
|
6 | 3 |
|
7 | 4 |
public class OrderBean { |
8 |
- public String orderId; |
|
9 |
- public float orderMoney; |
|
10 |
- public long orderTime; |
|
5 |
+ public String photoId; |
|
6 |
+ public String sessionId; |
|
11 | 7 |
public String buyerId; |
12 | 8 |
public String buyerName; |
9 |
+ public long originExpireTime; |
|
13 | 10 |
public PhotoBean photoBean; |
14 | 11 |
} |
@@ -26,28 +26,6 @@ public class DBHelper extends SQLiteOpenHelper{ |
||
26 | 26 |
|
27 | 27 |
} |
28 | 28 |
|
29 |
- public static final String ORDER_INFO_TABLE = "order_info_table"; |
|
30 |
- |
|
31 |
- public interface ORDER_INFO_COLUMNS { |
|
32 |
- String ORDER_ID = "order_id"; |
|
33 |
- String ORDER_MONEY = "order_money"; |
|
34 |
- String ORDER_TIME = "order_time"; |
|
35 |
- String BUYER_ID = "buyer_id"; |
|
36 |
- String BUYER_NAME = "buyer_name"; |
|
37 |
- String PHOTO_ID = "photo_id"; |
|
38 |
- String PHOTO_NAME = "photo_name"; |
|
39 |
- String PHOTO_PATH = "photo_path"; |
|
40 |
- String CAPTURE_TIME = "capture_time"; |
|
41 |
- String SESSION_ID = "session_id"; |
|
42 |
- String LENSMAN_ID = "lensman_id"; |
|
43 |
- String SESSION_DATE = "session_date"; |
|
44 |
- String SESSION_SEQ = "session_seq"; |
|
45 |
- String IS_RAW_PHOTO= "is_raw_photo"; |
|
46 |
- String UPLOADED_STATUS = "upload_status"; |
|
47 |
- |
|
48 |
- } |
|
49 |
- |
|
50 |
- |
|
51 | 29 |
private DBHelper(Context context){ |
52 | 30 |
super(context,DB_NAME,null,DB_VERSION); |
53 | 31 |
} |
@@ -71,10 +49,8 @@ public class DBHelper extends SQLiteOpenHelper{ |
||
71 | 49 |
|
72 | 50 |
private void createTables(SQLiteDatabase db){ |
73 | 51 |
createPhotoTable(db,PHOTO_INFO_TABLE); |
74 |
- createOrderTable(db,ORDER_INFO_TABLE); |
|
75 | 52 |
} |
76 | 53 |
|
77 |
- |
|
78 | 54 |
private void createPhotoTable(SQLiteDatabase db, String tableName){ |
79 | 55 |
StringBuilder sql = new StringBuilder(); |
80 | 56 |
sql.append("CREATE TABLE IF NOT EXISTS "); |
@@ -93,29 +69,4 @@ public class DBHelper extends SQLiteOpenHelper{ |
||
93 | 69 |
db.execSQL(sql.toString()); |
94 | 70 |
} |
95 | 71 |
|
96 |
- private void createOrderTable(SQLiteDatabase db, String tableName){ |
|
97 |
- StringBuilder sql = new StringBuilder(); |
|
98 |
- sql.append("CREATE TABLE IF NOT EXISTS "); |
|
99 |
- sql.append(tableName).append("("); |
|
100 |
- sql.append(ORDER_INFO_COLUMNS.PHOTO_ID).append(" LONG PRIMARY KEY, "); |
|
101 |
- |
|
102 |
- sql.append(ORDER_INFO_COLUMNS.ORDER_ID).append(" VARCHAR, "); |
|
103 |
- sql.append(ORDER_INFO_COLUMNS.BUYER_ID).append(" VARCHAR, "); |
|
104 |
- sql.append(ORDER_INFO_COLUMNS.BUYER_NAME).append(" VARCHAR, "); |
|
105 |
- sql.append(ORDER_INFO_COLUMNS.ORDER_MONEY).append(" FLOAT, "); |
|
106 |
- sql.append(ORDER_INFO_COLUMNS.ORDER_TIME).append(" LONG, "); |
|
107 |
- |
|
108 |
- sql.append(ORDER_INFO_COLUMNS.PHOTO_NAME).append(" VARCHAR, "); |
|
109 |
- sql.append(ORDER_INFO_COLUMNS.PHOTO_PATH).append(" VARCHAR, "); |
|
110 |
- sql.append(ORDER_INFO_COLUMNS.LENSMAN_ID).append(" VARCHAR, "); |
|
111 |
- sql.append(ORDER_INFO_COLUMNS.SESSION_ID).append(" VARCHAR, "); |
|
112 |
- sql.append(ORDER_INFO_COLUMNS.IS_RAW_PHOTO).append(" INTEGER, "); |
|
113 |
- sql.append(ORDER_INFO_COLUMNS.SESSION_SEQ).append(" INTEGER, "); |
|
114 |
- sql.append(ORDER_INFO_COLUMNS.SESSION_DATE).append(" LONG, "); |
|
115 |
- sql.append(ORDER_INFO_COLUMNS.UPLOADED_STATUS).append(" INTEGER, "); |
|
116 |
- sql.append(ORDER_INFO_COLUMNS.CAPTURE_TIME).append(" LONG "); |
|
117 |
- sql.append(")"); |
|
118 |
- db.execSQL(sql.toString()); |
|
119 |
- } |
|
120 |
- |
|
121 | 72 |
} |
@@ -10,7 +10,6 @@ import com.android.common.utils.LogHelper; |
||
10 | 10 |
import java.util.ArrayList; |
11 | 11 |
|
12 | 12 |
import ai.pai.lensman.App; |
13 |
-import ai.pai.lensman.bean.OrderBean; |
|
14 | 13 |
import ai.pai.lensman.bean.PhotoBean; |
15 | 14 |
import ai.pai.lensman.bean.SessionBean; |
16 | 15 |
|
@@ -18,7 +17,7 @@ import ai.pai.lensman.bean.SessionBean; |
||
18 | 17 |
public class DBService { |
19 | 18 |
|
20 | 19 |
private static DBService instance; |
21 |
- private static Object DB_LOCK = new Object(); |
|
20 |
+ private static final Object DB_LOCK = new Object(); |
|
22 | 21 |
private DBHelper dbHelper; |
23 | 22 |
|
24 | 23 |
private static final String TAG = "DBService"; |
@@ -235,14 +234,6 @@ public class DBService { |
||
235 | 234 |
if (c.moveToNext()) { |
236 | 235 |
photoBean = cursor2PhotoBean(c); |
237 | 236 |
} |
238 |
-// else { |
|
239 |
-// c = db.rawQuery("select * from " + DBHelper.PHOTO_INFO_TABLE + " where " |
|
240 |
-// + DBHelper.PHOTO_INFO_COLUMNS.UPLOADED_STATUS + " = '" + -1 + "'"+" order by " |
|
241 |
-// + DBHelper.PHOTO_INFO_COLUMNS.CAPTURE_TIME + " desc limit 1 ", null); |
|
242 |
-// if (c.moveToNext()) { |
|
243 |
-// photoBean = cursor2PhotoBean(c); |
|
244 |
-// } |
|
245 |
-// } |
|
246 | 237 |
db.setTransactionSuccessful(); |
247 | 238 |
} catch (Exception e) { |
248 | 239 |
LogHelper.d(TAG, "dbservice getNextUploadPhotoBean error happen " + e); |
@@ -258,103 +249,4 @@ public class DBService { |
||
258 | 249 |
return photoBean; |
259 | 250 |
} |
260 | 251 |
|
261 |
- public void addOrderBean(OrderBean bean){ |
|
262 |
- SQLiteDatabase db = null; |
|
263 |
- synchronized (DB_LOCK) { |
|
264 |
- try { |
|
265 |
- db = dbHelper.getWritableDatabase(); |
|
266 |
- db.beginTransaction(); |
|
267 |
- db.insertWithOnConflict(DBHelper.ORDER_INFO_TABLE, null, orderBean2ContentValues(bean), |
|
268 |
- SQLiteDatabase.CONFLICT_REPLACE); |
|
269 |
- db.setTransactionSuccessful(); |
|
270 |
- } catch (Exception e) { |
|
271 |
- LogHelper.d(TAG, "dbservice addOrderBean error happen " + e); |
|
272 |
- } finally { |
|
273 |
- try { |
|
274 |
- db.endTransaction(); |
|
275 |
- } catch (Exception e) { |
|
276 |
- e.printStackTrace(); |
|
277 |
- } |
|
278 |
- closeDB(db); |
|
279 |
- } |
|
280 |
- } |
|
281 |
- } |
|
282 |
- |
|
283 |
- public void updateOrderBean(OrderBean bean){ |
|
284 |
- addOrderBean(bean); |
|
285 |
- } |
|
286 |
- |
|
287 |
- |
|
288 |
- private OrderBean cursor2OrderBean(Cursor c) { |
|
289 |
- OrderBean item = new OrderBean(); |
|
290 |
- item.buyerId = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.BUYER_ID)); |
|
291 |
- item.buyerName= c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.BUYER_NAME)); |
|
292 |
- item.orderId = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.ORDER_ID)); |
|
293 |
- item.orderMoney= c.getFloat(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.ORDER_MONEY)); |
|
294 |
- item.orderTime = c.getLong(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.ORDER_TIME)); |
|
295 |
- item.photoBean = new PhotoBean(); |
|
296 |
- item.photoBean.lensmanId = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.LENSMAN_ID)); |
|
297 |
- item.photoBean.sessionId = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.SESSION_ID)); |
|
298 |
- item.photoBean.isRawPhoto =(c.getInt(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.IS_RAW_PHOTO))>0); |
|
299 |
- item.photoBean.uploadStatus = c.getInt(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.UPLOADED_STATUS)); |
|
300 |
- item.photoBean.captureTime = c.getLong(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.CAPTURE_TIME)); |
|
301 |
- item.photoBean.photoId = c.getLong(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.PHOTO_ID)); |
|
302 |
- item.photoBean.photoName = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.PHOTO_NAME)); |
|
303 |
- item.photoBean.photoPath = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.PHOTO_PATH)); |
|
304 |
- item.photoBean.sessionDate = c.getLong(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.SESSION_DATE)); |
|
305 |
- item.photoBean.sessionSeq = c.getInt(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.SESSION_SEQ)); |
|
306 |
- return item; |
|
307 |
- } |
|
308 |
- |
|
309 |
- private ContentValues orderBean2ContentValues(OrderBean orderBean) { |
|
310 |
- ContentValues cv = new ContentValues(); |
|
311 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.BUYER_ID, orderBean.buyerId); |
|
312 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.BUYER_NAME,orderBean.buyerName); |
|
313 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.ORDER_ID,orderBean.orderId); |
|
314 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.ORDER_MONEY,orderBean.orderMoney); |
|
315 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.ORDER_TIME,orderBean.orderTime); |
|
316 |
- PhotoBean item = orderBean.photoBean; |
|
317 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.CAPTURE_TIME, item.captureTime); |
|
318 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.IS_RAW_PHOTO, item.isRawPhoto ? 1: 0); |
|
319 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.PHOTO_ID, item.photoId); |
|
320 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.PHOTO_NAME, item.photoName); |
|
321 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.PHOTO_PATH, item.photoPath); |
|
322 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.SESSION_ID, item.sessionId); |
|
323 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.LENSMAN_ID,item.lensmanId); |
|
324 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.UPLOADED_STATUS,item.uploadStatus); |
|
325 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.SESSION_DATE,item.sessionDate); |
|
326 |
- cv.put(DBHelper.ORDER_INFO_COLUMNS.SESSION_SEQ,item.sessionSeq); |
|
327 |
- return cv; |
|
328 |
- } |
|
329 |
- |
|
330 |
- public OrderBean getNextDealOrder(){ |
|
331 |
- LogHelper.d(TAG, "dbservice getNextDealOrder "); |
|
332 |
- OrderBean orderBean = null; |
|
333 |
- SQLiteDatabase db = null; |
|
334 |
- Cursor c = null; |
|
335 |
- synchronized (DB_LOCK) { |
|
336 |
- try { |
|
337 |
- db = dbHelper.getReadableDatabase(); |
|
338 |
- db.beginTransaction(); |
|
339 |
- c = db.rawQuery("select * from " + DBHelper.ORDER_INFO_TABLE + " where " |
|
340 |
- + DBHelper.ORDER_INFO_COLUMNS.UPLOADED_STATUS + " = '" + 0 + "'"+" order by " |
|
341 |
- + DBHelper.ORDER_INFO_COLUMNS.ORDER_TIME + " desc limit 1 ", null); |
|
342 |
- if (c.moveToNext()) { |
|
343 |
- orderBean = cursor2OrderBean(c); |
|
344 |
- } |
|
345 |
- db.setTransactionSuccessful(); |
|
346 |
- } catch (Exception e) { |
|
347 |
- LogHelper.d(TAG, "dbservice getNextDealOrder error happen " + e); |
|
348 |
- } finally { |
|
349 |
- try { |
|
350 |
- db.endTransaction(); |
|
351 |
- } catch (Exception e) { |
|
352 |
- e.printStackTrace(); |
|
353 |
- } |
|
354 |
- closeCursorAndDB(c, db); |
|
355 |
- } |
|
356 |
- } |
|
357 |
- return orderBean; |
|
358 |
- } |
|
359 |
- |
|
360 | 252 |
} |
@@ -21,10 +21,9 @@ import java.net.HttpURLConnection; |
||
21 | 21 |
import java.net.URL; |
22 | 22 |
import java.util.ArrayList; |
23 | 23 |
import java.util.HashMap; |
24 |
-import java.util.Timer; |
|
25 |
-import java.util.TimerTask; |
|
26 | 24 |
|
27 | 25 |
import ai.pai.lensman.bean.OrderBean; |
26 |
+import ai.pai.lensman.bean.PhotoBean; |
|
28 | 27 |
import ai.pai.lensman.db.Preferences; |
29 | 28 |
import ai.pai.lensman.utils.BoxUrlContainer; |
30 | 29 |
import ai.pai.lensman.utils.Constants; |
@@ -72,13 +71,18 @@ public class OrderDealService extends Service implements Handler.Callback{ |
||
72 | 71 |
int status = json.getInt("status"); |
73 | 72 |
if (status == 200) { |
74 | 73 |
JSONObject data = json.getJSONObject("data"); |
75 |
- JSONArray orders = data.getJSONArray("files"); |
|
74 |
+ JSONArray orders = data.getJSONArray("wanted"); |
|
76 | 75 |
if (orders != null && orders.length() > 0) { |
77 | 76 |
orderList = new ArrayList<OrderBean>(); |
78 | 77 |
for (int k = 0; k < orders.length(); k++) { |
79 | 78 |
JSONObject orderObj = orders.getJSONObject(k); |
80 | 79 |
OrderBean bean = new OrderBean(); |
81 |
- |
|
80 |
+ bean.sessionId = orderObj.getString("session_id"); |
|
81 |
+ bean.photoId = orderObj.getString("photo_id"); |
|
82 |
+ JSONObject photoObj = orderObj.getJSONObject("group_photo_info"); |
|
83 |
+ bean.buyerId = photoObj.getString("user_id"); |
|
84 |
+ bean.buyerName = photoObj.getString("nickname"); |
|
85 |
+ bean.originExpireTime = photoObj.getLong("origin_expired_stamps"); |
|
82 | 86 |
orderList.add(bean); |
83 | 87 |
} |
84 | 88 |
} |
@@ -116,13 +120,12 @@ public class OrderDealService extends Service implements Handler.Callback{ |
||
116 | 120 |
} |
117 | 121 |
} |
118 | 122 |
|
119 |
- private void fetchOriginFromBox(OrderBean orderBean) { |
|
123 |
+ private void fetchOriginFromBox(final OrderBean orderBean) { |
|
120 | 124 |
HashMap<String, String> params = new HashMap<>(); |
121 | 125 |
params.put("lensman", Preferences.getInstance().getLensManId()); |
122 |
- params.put("session", orderBean.photoBean.sessionId); |
|
123 |
- params.put("name", orderBean.photoBean.photoName); |
|
126 |
+ params.put("session", orderBean.sessionId); |
|
127 |
+ params.put("name", orderBean.photoId); |
|
124 | 128 |
new HttpPostTask(params) { |
125 |
- OrderBean bean = new OrderBean(); |
|
126 | 129 |
|
127 | 130 |
@Override |
128 | 131 |
protected boolean parseResponse(String response) { |
@@ -132,7 +135,17 @@ public class OrderDealService extends Service implements Handler.Callback{ |
||
132 | 135 |
int status = json.getInt("status"); |
133 | 136 |
if (status == 200) { |
134 | 137 |
JSONObject data = json.getJSONObject("data"); |
135 |
- //TODO |
|
138 |
+ JSONObject file = data.getJSONObject("origin"); |
|
139 |
+ PhotoBean bean = new PhotoBean(); |
|
140 |
+ bean.photoName = file.getString("name"); |
|
141 |
+ bean.photoId = file.getLong("id"); |
|
142 |
+ bean.photoPath = file.getString("path"); |
|
143 |
+ bean.captureTime = bean.photoId; |
|
144 |
+ bean.isRawPhoto = false; |
|
145 |
+ bean.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN; |
|
146 |
+ bean.sessionId = orderBean.sessionId; |
|
147 |
+ bean.lensmanId = Preferences.getInstance().getLensManId(); |
|
148 |
+ orderBean.photoBean = bean; |
|
136 | 149 |
} |
137 | 150 |
return true; |
138 | 151 |
} catch (Exception e) { |
@@ -144,14 +157,14 @@ public class OrderDealService extends Service implements Handler.Callback{ |
||
144 | 157 |
@Override |
145 | 158 |
protected void onPostFail() { |
146 | 159 |
super.onPostFail(); |
147 |
- orderList.remove(bean); |
|
160 |
+ orderList.remove(orderBean); |
|
148 | 161 |
dealOrder(); |
149 | 162 |
} |
150 | 163 |
|
151 | 164 |
@Override |
152 | 165 |
protected void onPostSuccess() { |
153 | 166 |
super.onPostSuccess(); |
154 |
- new SavePhotoTask(bean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), bean); |
|
167 |
+ new SavePhotoTask(orderBean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), orderBean); |
|
155 | 168 |
} |
156 | 169 |
}.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.FETCH_ORIGIN_URL); |
157 | 170 |
|
@@ -259,7 +272,7 @@ public class OrderDealService extends Service implements Handler.Callback{ |
||
259 | 272 |
protected Boolean doInBackground(Void... params) { |
260 | 273 |
for (int k = 0; k < 5; k++) { |
261 | 274 |
try { |
262 |
- String dirPath = ai.pai.lensman.utils.Constants.APP_IMAGE_DIR + File.separator + bean.photoBean.sessionId |
|
275 |
+ String dirPath = ai.pai.lensman.utils.Constants.APP_IMAGE_DIR + File.separator + bean.sessionId |
|
263 | 276 |
+ File.separator + Constants.ORIGIN_DIR_NAME; |
264 | 277 |
File dir = new File(dirPath); |
265 | 278 |
dir.mkdirs(); |