@@ -26,6 +26,27 @@ 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 |
+ |
|
| 29 | 50 |
|
| 30 | 51 |
private DBHelper(Context context){
|
| 31 | 52 |
super(context,DB_NAME,null,DB_VERSION); |
@@ -50,6 +71,7 @@ public class DBHelper extends SQLiteOpenHelper{
|
||
| 50 | 71 |
|
| 51 | 72 |
private void createTables(SQLiteDatabase db){
|
| 52 | 73 |
createPhotoTable(db,PHOTO_INFO_TABLE); |
| 74 |
+ createOrderTable(db,ORDER_INFO_TABLE); |
|
| 53 | 75 |
} |
| 54 | 76 |
|
| 55 | 77 |
|
@@ -71,4 +93,29 @@ public class DBHelper extends SQLiteOpenHelper{
|
||
| 71 | 93 |
db.execSQL(sql.toString()); |
| 72 | 94 |
} |
| 73 | 95 |
|
| 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 |
+ |
|
| 74 | 121 |
} |
@@ -0,0 +1,92 @@ |
||
| 1 |
+package ai.pai.lensman.service; |
|
| 2 |
+ |
|
| 3 |
+import android.app.Service; |
|
| 4 |
+import android.content.Intent; |
|
| 5 |
+import android.os.Binder; |
|
| 6 |
+import android.os.IBinder; |
|
| 7 |
+ |
|
| 8 |
+import com.android.common.executors.ThreadExecutor; |
|
| 9 |
+import com.android.common.utils.LogHelper; |
|
| 10 |
+ |
|
| 11 |
+import ai.pai.lensman.bean.PhotoBean; |
|
| 12 |
+import ai.pai.lensman.db.DBService; |
|
| 13 |
+ |
|
| 14 |
+public class OrderDealService extends Service implements UploadTask.OnPhotoUploadListener{
|
|
| 15 |
+ |
|
| 16 |
+ private PhotoBean currentPhoto; |
|
| 17 |
+ private PhotoUploadListener listener; |
|
| 18 |
+ |
|
| 19 |
+ @Override |
|
| 20 |
+ public IBinder onBind(Intent intent) {
|
|
| 21 |
+ return new MyBinder(); |
|
| 22 |
+ } |
|
| 23 |
+ |
|
| 24 |
+ @Override |
|
| 25 |
+ public int onStartCommand(Intent intent, int flags, int startId) {
|
|
| 26 |
+ if(intent!=null && intent.getSerializableExtra("photo")!=null){
|
|
| 27 |
+ PhotoBean bean = (PhotoBean) intent.getSerializableExtra("photo");
|
|
| 28 |
+ bean.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN; |
|
| 29 |
+ DBService.getInstance().updatePhotoBean(bean); |
|
| 30 |
+ } |
|
| 31 |
+ startUpload(); |
|
| 32 |
+ return super.onStartCommand(intent, flags, startId); |
|
| 33 |
+ } |
|
| 34 |
+ |
|
| 35 |
+ private synchronized void startUpload(){
|
|
| 36 |
+ if(currentPhoto!=null){
|
|
| 37 |
+ LogHelper.d("czy","当前有图片正在上传"+currentPhoto);
|
|
| 38 |
+ return; |
|
| 39 |
+ } |
|
| 40 |
+ currentPhoto = DBService.getInstance().getNextUploadPhoto(); |
|
| 41 |
+ if(currentPhoto==null){
|
|
| 42 |
+ LogHelper.d("czy","本地图片已全部上传");
|
|
| 43 |
+ return; |
|
| 44 |
+ } |
|
| 45 |
+ LogHelper.d("czy","即将上传的照片是"+currentPhoto);
|
|
| 46 |
+ new UploadTask(currentPhoto,this).executeOnExecutor(ThreadExecutor.getInstance().getExecutor()); |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ @Override |
|
| 50 |
+ public void onPhotoUploadSucceed(PhotoBean bean) {
|
|
| 51 |
+ if(bean.equals(currentPhoto)){
|
|
| 52 |
+ currentPhoto.uploadStatus = PhotoBean.UploadStatus.STATUS_SUCCESS; |
|
| 53 |
+ DBService.getInstance().updatePhotoBean(currentPhoto); |
|
| 54 |
+ if(listener!=null){
|
|
| 55 |
+ listener.onPhotoUploaded(currentPhoto); |
|
| 56 |
+ } |
|
| 57 |
+ currentPhoto = null; |
|
| 58 |
+ } |
|
| 59 |
+ startUpload(); |
|
| 60 |
+ } |
|
| 61 |
+ |
|
| 62 |
+ @Override |
|
| 63 |
+ public void onPhotoUploadFail(PhotoBean bean) {
|
|
| 64 |
+ if(bean.equals(currentPhoto)){
|
|
| 65 |
+ currentPhoto.uploadStatus = PhotoBean.UploadStatus.STATUS_ERROR; |
|
| 66 |
+ DBService.getInstance().updatePhotoBean(currentPhoto); |
|
| 67 |
+ if(listener!=null){
|
|
| 68 |
+ listener.onPhotoUploadError(currentPhoto); |
|
| 69 |
+ } |
|
| 70 |
+ currentPhoto = null; |
|
| 71 |
+ } |
|
| 72 |
+ startUpload(); |
|
| 73 |
+ } |
|
| 74 |
+ |
|
| 75 |
+ public void setPhotoUploadListener(PhotoUploadListener listener){
|
|
| 76 |
+ this.listener = listener; |
|
| 77 |
+ } |
|
| 78 |
+ |
|
| 79 |
+ public interface PhotoUploadListener{
|
|
| 80 |
+ void onPhotoUploaded(PhotoBean bean); |
|
| 81 |
+ void onPhotoUploadError(PhotoBean bean); |
|
| 82 |
+ } |
|
| 83 |
+ |
|
| 84 |
+ public class MyBinder extends Binder {
|
|
| 85 |
+ |
|
| 86 |
+ public OrderDealService getService(){
|
|
| 87 |
+ return OrderDealService.this; |
|
| 88 |
+ } |
|
| 89 |
+ |
|
| 90 |
+ } |
|
| 91 |
+ |
|
| 92 |
+} |