Quellcode durchsuchen

RA Image

移植上传模块
Ray Zhang vor 9 Jahren
Ursprung
Commit
fbc26da232

+ 18 - 0
RA Image/RA Image.xcodeproj/project.pbxproj

@@ -51,6 +51,9 @@
 		71114AF11EB2DEF900D2200C /* ScannerControllerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 71114AE91EB2DEF900D2200C /* ScannerControllerView.m */; };
 		71114AF21EB2DEF900D2200C /* ScannerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71114AEB1EB2DEF900D2200C /* ScannerViewController.m */; };
 		71114AF31EB2DEF900D2200C /* SCShapeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 71114AED1EB2DEF900D2200C /* SCShapeView.m */; };
+		71961CB01EC00DDD002C4096 /* RANetworkTaskDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 71961CAB1EC00DDD002C4096 /* RANetworkTaskDelegate.m */; };
+		71961CB11EC00DDD002C4096 /* RAUploadManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 71961CAD1EC00DDD002C4096 /* RAUploadManager.m */; };
+		71961CB21EC00DDD002C4096 /* RAUploadOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 71961CAF1EC00DDD002C4096 /* RAUploadOperation.m */; };
 		71DCDC391EAF234E00BA045A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 71DCDC381EAF234E00BA045A /* main.m */; };
 		71DCDC3C1EAF234E00BA045A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 71DCDC3B1EAF234E00BA045A /* AppDelegate.m */; };
 		71DCDC3F1EAF234E00BA045A /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71DCDC3E1EAF234E00BA045A /* RootViewController.m */; };
@@ -145,6 +148,12 @@
 		71114AEB1EB2DEF900D2200C /* ScannerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ScannerViewController.m; path = ../../common/ScannerViewController.m; sourceTree = "<group>"; };
 		71114AEC1EB2DEF900D2200C /* SCShapeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SCShapeView.h; path = ../../common/SCShapeView.h; sourceTree = "<group>"; };
 		71114AED1EB2DEF900D2200C /* SCShapeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SCShapeView.m; path = ../../common/SCShapeView.m; sourceTree = "<group>"; };
+		71961CAA1EC00DDD002C4096 /* RANetworkTaskDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RANetworkTaskDelegate.h; path = ../../common/upload/RANetworkTaskDelegate.h; sourceTree = "<group>"; };
+		71961CAB1EC00DDD002C4096 /* RANetworkTaskDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RANetworkTaskDelegate.m; path = ../../common/upload/RANetworkTaskDelegate.m; sourceTree = "<group>"; };
+		71961CAC1EC00DDD002C4096 /* RAUploadManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RAUploadManager.h; path = ../../common/upload/RAUploadManager.h; sourceTree = "<group>"; };
+		71961CAD1EC00DDD002C4096 /* RAUploadManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RAUploadManager.m; path = ../../common/upload/RAUploadManager.m; sourceTree = "<group>"; };
+		71961CAE1EC00DDD002C4096 /* RAUploadOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RAUploadOperation.h; path = ../../common/upload/RAUploadOperation.h; sourceTree = "<group>"; };
+		71961CAF1EC00DDD002C4096 /* RAUploadOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RAUploadOperation.m; path = ../../common/upload/RAUploadOperation.m; sourceTree = "<group>"; };
 		71DCDC341EAF234E00BA045A /* RA Image.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "RA Image.app"; sourceTree = BUILT_PRODUCTS_DIR; };
 		71DCDC381EAF234E00BA045A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
 		71DCDC3A1EAF234E00BA045A /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@@ -229,6 +238,12 @@
 		42A829C91EBC6BF500898B8A /* Upload */ = {
 			isa = PBXGroup;
 			children = (
+				71961CAA1EC00DDD002C4096 /* RANetworkTaskDelegate.h */,
+				71961CAB1EC00DDD002C4096 /* RANetworkTaskDelegate.m */,
+				71961CAC1EC00DDD002C4096 /* RAUploadManager.h */,
+				71961CAD1EC00DDD002C4096 /* RAUploadManager.m */,
+				71961CAE1EC00DDD002C4096 /* RAUploadOperation.h */,
+				71961CAF1EC00DDD002C4096 /* RAUploadOperation.m */,
 				42A829CA1EBC6CA200898B8A /* UploadViewController.h */,
 				42A829CB1EBC6CA200898B8A /* UploadViewController.m */,
 				42A829CD1EBC6CA900898B8A /* Upload.storyboard */,
@@ -581,12 +596,14 @@
 				71114AA31EB1C40900D2200C /* RAINetwork.m in Sources */,
 				71114AC91EB1C73B00D2200C /* zip.c in Sources */,
 				71114AF31EB2DEF900D2200C /* SCShapeView.m in Sources */,
+				71961CB11EC00DDD002C4096 /* RAUploadManager.m in Sources */,
 				71114AF21EB2DEF900D2200C /* ScannerViewController.m in Sources */,
 				42BC2D091EBAC75F0016B30D /* TouchImageView.m in Sources */,
 				42A829C31EBC0F8300898B8A /* ManufacturerListController.m in Sources */,
 				71114AB61EB1C5C800D2200C /* NSString+Base64.m in Sources */,
 				71114AA61EB1C50D00D2200C /* RAUtils.m in Sources */,
 				71DCDC3C1EAF234E00BA045A /* AppDelegate.m in Sources */,
+				71961CB21EC00DDD002C4096 /* RAUploadOperation.m in Sources */,
 				42E1B1021EB1C92000EEF27C /* BasicViewController.m in Sources */,
 				426E6B1F1EB8558400942BE1 /* RootModeCell.m in Sources */,
 				71DCDC391EAF234E00BA045A /* main.m in Sources */,
@@ -594,6 +611,7 @@
 				71114ABC1EB1C73400D2200C /* ZipArchive.mm in Sources */,
 				42056E871EB9CF5D0010597A /* BasicModeViewController.m in Sources */,
 				42E1B0FE1EB1C8EE00EEF27C /* LoginTextFiledCell.m in Sources */,
+				71961CB01EC00DDD002C4096 /* RANetworkTaskDelegate.m in Sources */,
 				42A829D21EBC6D3300898B8A /* UploadCell.m in Sources */,
 				71114AB41EB1C5C800D2200C /* NSData+Base64.m in Sources */,
 				71114ACF1EB1C79300D2200C /* Reachability.m in Sources */,

BIN
RA Image/RA Image.xcodeproj/project.xcworkspace/xcuserdata/ray.xcuserdatad/UserInterfaceState.xcuserstate


+ 2 - 1
RA Image/RA Image/AppDelegate.h

@@ -7,6 +7,7 @@
 //
 
 #import <UIKit/UIKit.h>
+#import "RAUploadManager.h"
 
 @interface AppDelegate : UIResponder <UIApplicationDelegate>
 
@@ -26,6 +27,6 @@
 - (void)showLoginVC;
 - (void)logout;
 - (void)loadCompanyIcon:(NSString *)url;
-
+@property (strong, nonatomic)  RAUploadManager *uploadManager;
 @end
 

+ 3 - 0
RA Image/RA Image/AppDelegate.m

@@ -61,6 +61,9 @@
     NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
     self.build =[infoDict objectForKey:@"CFBundleVersion"];
     self.rootVC = self.window.rootViewController;
+    
+    self.uploadManager=[[RAUploadManager alloc] init];
+    self.uploadManager.maxRetry = 2;
     return YES;
 }
 

+ 47 - 2
RA Image/RA Image/PopModeViewController.m

@@ -6,6 +6,8 @@
 //  Copyright © 2017年 USAI. All rights reserved.
 //
 
+#import "config.h"
+
 #import "PopModeViewController.h"
 #import "UploadViewController.h"
 
@@ -48,8 +50,51 @@
 }
 
 - (IBAction)uploadBtnClick:(UIButton *)sender {
-    UploadViewController *upVC = (UploadViewController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadViewController"];
-    [self.navigationController pushViewController:upVC animated:YES];
+    
+    // check piid, photo...
+    if(self.barcode.length ==0)
+    {
+    [RAUtils message_alert:@"Barcode cann't be blank" title:@"Warning" controller:self];
+    return;
+    }
+    if(self.photos.count ==0)
+    {
+        [RAUtils message_alert:@"You must take at least one photo." title:@"Warning" controller:self];
+        return;
+    }
+    AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
+    
+    
+    
+    //prepare upload
+    NSMutableArray* tasks = [NSMutableArray new];
+    
+    for(NSMutableDictionary* photo in self.photos)
+    {
+            NSMutableDictionary* task=[[NSMutableDictionary alloc]init];
+        
+        
+            task[@"file_path"]=photo[@"path"];
+            task[@"url"]=Appdelegate.address;
+        
+            NSDictionary* params = @{@"user" : Appdelegate.user,@"password" : Appdelegate.password,@"mode":@"piid",@"barcode":self.barcode,@"_operate":@"uoload"};
+            task[@"params"]=params;
+        [tasks addObject:task];
+
+    }
+
+    
+ //    // add upload tasks;
+
+
+    [Appdelegate.uploadManager addTasks:nil];
+    
+    
+    
+    
+//    
+//    UploadViewController *upVC = (UploadViewController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadViewController"];
+//    [self.navigationController pushViewController:upVC animated:YES];
 }
 
 - (IBAction)typeBtnClick:(UIButton *)sender {

+ 97 - 19
RA Image/RA Image/UploadViewController.m

@@ -31,33 +31,111 @@
 #pragma mark - TableView DataSource
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    return 10;
+    AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
+    return Appdelegate.uploadManager.arr_queue.count;
 }
 
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-    UploadCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UploadCell"];
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
+    
+    
+    
+    
+    {
+        NSString *CellIdentifier = @"UploadCell";
+        UploadCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+        NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row];
+        
+        
+        
+        NSString* status =nil;
+        switch ([item_json[@"status"] intValue]) {
+            case TaskStatusStart:
+                status=@"uploading";
+                break;
+            case TaskStatusStop:
+                status=@"stop";
+                break;
+            case TaskStatusError:
+                status=@"error";
+                break;
+            case TaskStatusWait:
+                status=@"waiting";
+                break;
+            case TaskStatusFinish:
+                status=@"finish";
+                break;
+                
+            default:
+                status=@"error";
+                break;
+        }
+        
+        double progress =[item_json[@"progress"] doubleValue];
+        cell.progress=progress;
+        cell.name=[item_json[@"file_path"] lastPathComponent];
+        cell.state=  status;
+        
+        RAUploadOperation* op = item_json[@"operation"];
+        op.updateUI=^(){
+            
+            
+            NSString* status =nil;
+            switch ([item_json[@"status"] intValue]) {
+                case TaskStatusStart:
+                    status=@"uploading";
+                    break;
+                case TaskStatusStop:
+                    status=@"stop";
+                    break;
+                case TaskStatusError:
+                    status=@"error";
+                    break;
+                case TaskStatusWait:
+                    status=@"waiting";
+                    break;
+                case TaskStatusFinish:
+                    status=@"finish";
+                    break;
+                    
+                default:
+                    status=@"error";
+                    break;
+            }
+            double progress =[item_json[@"progress"] doubleValue];
+            cell.progress=progress;
+            cell.name=[item_json[@"file_path"] lastPathComponent];
+            cell.state=  status;
+            //               cell.labelname.text=[item_json[@"file_path"] lastPathComponent];
+            
+        };
+        //
+        return cell;
+    }
     
-    return cell;
 }
 
 #pragma mark - TableView Delegate
 
-- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
-    UploadCell *upCell = (UploadCell *)cell;
-    upCell.name = @"QS-WPS00889-OPQ-WQER";
-    upCell.progress = indexPath.row / 10.0;
-    upCell.state = @"Uploading...";
-    if (indexPath.row > 5) {
-        upCell.state = @"Waiting...";
-    }
-}
+//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
+//    UploadCell *upCell = (UploadCell *)cell;
+//    upCell.name = @"QS-WPS00889-OPQ-WQER";
+//    upCell.progress = indexPath.row / 10.0;
+//    upCell.state = @"Uploading...";
+//    if (indexPath.row > 5) {
+//        upCell.state = @"Waiting...";
+//    }
+//}
+//
+//- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
+//    UploadCell *upCell = (UploadCell *)cell;
+//    upCell.name = nil;
+//    upCell.progress = 0;
+//    upCell.state = nil;
+//}
+
 
-- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
-    UploadCell *upCell = (UploadCell *)cell;
-    upCell.name = nil;
-    upCell.progress = 0;
-    upCell.state = nil;
-}
 
 
 @end

+ 19 - 16
RA Image/RA Image/config.h

@@ -18,7 +18,7 @@
 //#define ENCRYPT_OFF
 # ifdef DEBUG
 #define NO_SAVE_VERIFY true
-//    #define test_server
+    #define test_server
 # else
 #define NO_SAVE_VERIFY false
 # endif
@@ -39,22 +39,25 @@
 
 
 #define  URL_ERR_LOG  @""
-#define  URL_UPDATE_AUTH  @"http://192.168.0.155/cms/phpcms/admin_new.php"
-#define  URL_UPLOAD_PDF  @"http://192.168.0.155/cms/phpcms/admin_new.php"
-#define  URL_LOGOUT  @"http://192.168.0.155/cms/phpcms/admin_new.php"
-#define  URL_NEW_DOCUMENT  @"http://192.168.0.155/cms/phpcms/admin_new.php"
-#define  URL_UPDATE_NOTES  @"http://192.168.0.155/cms/phpcms/admin_new.php"
-#define  URL_REQUEST_DOC  @"http://192.168.0.155/cms/phpcms/admin_new.php"
-#define URL_HEART_BEAT @"http://192.168.0.155/cms/phpcms/admin_new.php"
+//#define  URL_UPDATE_AUTH  @"http://192.168.0.155/cms/phpcms/admin_new.php"
+//#define  URL_UPLOAD_PDF  @"http://192.168.0.155/cms/phpcms/admin_new.php"
+//#define  URL_LOGOUT  @"http://192.168.0.155/cms/phpcms/admin_new.php"
+//#define  URL_NEW_DOCUMENT  @"http://192.168.0.155/cms/phpcms/admin_new.php"
+//#define  URL_UPDATE_NOTES  @"http://192.168.0.155/cms/phpcms/admin_new.php"
+//#define  URL_REQUEST_DOC  @"http://192.168.0.155/cms/phpcms/admin_new.php"
+//#define URL_HEART_BEAT @"http://192.168.0.155/cms/phpcms/admin_new.php"
+#define URL_UPLOAD_PHOTO @"http://192.168.0.155/cms/phpcms/admin_new.php"
+
 #else
-#define  URL_ERR_LOG  @""
-#define  URL_UPDATE_AUTH  @"https://www.thegraniteexpo.com/admin_new.php"
-#define  URL_UPLOAD_PDF  @"https://www.thegraniteexpo.com/admin_new.php"
-#define  URL_LOGOUT  @"https://www.thegraniteexpo.com/admin_new.php"
-#define  URL_REQUEST_DOC  @"https://www.thegraniteexpo.com/admin_new.php"
-#define  URL_NEW_DOCUMENT  @"https://www.thegraniteexpo.com/admin_new.php"
-#define  URL_UPDATE_NOTES  @"https://www.thegraniteexpo.com/admin_new.php"
-#define URL_HEART_BEAT @"https://www.thegraniteexpo.com/admin_new.php"
+//#define  URL_ERR_LOG  @""
+//#define  URL_UPDATE_AUTH  @"https://www.thegraniteexpo.com/admin_new.php"
+//#define  URL_UPLOAD_PDF  @"https://www.thegraniteexpo.com/admin_new.php"
+//#define  URL_LOGOUT  @"https://www.thegraniteexpo.com/admin_new.php"
+//#define  URL_REQUEST_DOC  @"https://www.thegraniteexpo.com/admin_new.php"
+//#define  URL_NEW_DOCUMENT  @"https://www.thegraniteexpo.com/admin_new.php"
+//#define  URL_UPDATE_NOTES  @"https://www.thegraniteexpo.com/admin_new.php"
+//#define URL_HEART_BEAT @"https://www.thegraniteexpo.com/admin_new.php"
+#define URL_UPLOAD_PHOTO @"http://192.168.0.155/cms/phpcms/admin_new.php"
 #endif
 
 #endif /* config_h */