Просмотр исходного кода

修复Portfolio同步数据重复。

Pen Li 9 лет назад
Родитель
Сommit
81517aaca4

BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 24 - 11
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -10420,7 +10420,7 @@
     
     NSString *prodct_ids = [params objectForKey:@"product_id"];
 //    NSString *user = [params objectForKey:@"user"];
-    NSString *sql = [NSString stringWithFormat:@"insert into offline_portfolio (product_id,name,description,item_id,img) select * from (select p.product_id,p.name,p.description,p.item_id,i.url from product as p left join model_image as i on i.product_id = p.product_id  where p.product_id in (%@) and p.product_id not in (select product_id from offline_portfolio) and i.type = 1 group by  p.product_id order by i.default_img desc, i._id asc );insert into offline_portfolio (product_id,name,description,item_id,img,is_delete) select * from (select p.product_id,p.name,p.description,p.item_id,i.url,0 from product as p left join model_image as i on i.product_id = p.product_id  where p.product_id in (%@) and p.product_id in (select product_id from offline_portfolio where is_delete = 1) and i.type = 1 and (select count(0) from offline_portfolio where product_id = p.product_id) = 1 group by  p.product_id order by i.default_img desc, i._id asc );delete from offline_portfolio where (select count(0) from offline_portfolio where product_id in (%@)) > 1 and is_delete = 1;",prodct_ids,prodct_ids,prodct_ids];
+    NSString *sql = [NSString stringWithFormat:@"insert into offline_portfolio (product_id,name,description,item_id) select * from (select p.product_id,p.name,p.description,p.item_id from product as p where p.product_id in (%@));",prodct_ids];
     
     int result = [iSalesDB execSql:sql];
     
@@ -10595,7 +10595,7 @@
         qty = @"";
     }
     
-    NSString *where = [NSString stringWithFormat:@" where item_id in (%@);",item_ids];
+    NSString *where = [NSString stringWithFormat:@" where item_id in (%@) and (is_delete is null or is_delete = 0);",item_ids];
     sql = [sql stringByAppendingString:where];
     
     
@@ -10617,7 +10617,7 @@
     
     sqlite3 *db = [iSalesDB get_db];
     
-    NSString *sql = [NSString stringWithFormat:@"update offline_portfolio set is_delete = 1 where item_id in (%@);",portfolio_ids];
+    NSString *sql = [NSString stringWithFormat:@"update offline_portfolio set is_delete = 1 where item_id in (%@) and (is_delete is null or is_delete = 0);",portfolio_ids];
     
     int result = [iSalesDB execSql:sql db:db];
     
@@ -10720,12 +10720,16 @@
         
     }
     
-    NSString *sqlQuery =[NSString stringWithFormat:@"select _id,product_id,name,description,item_id,fashion_id,available_qty,percentage,percent,sheet_price,sheet_discount,img,line_note,is_delete,createtime,modifytime from offline_portfolio where %@",where];
+    NSString *sqlQuery =[NSString stringWithFormat:@"select _id,product_id,name,description,item_id,fashion_id,available_qty,percentage,percent,ifnull(sheet_price,'null'),sheet_discount,img,line_note,is_delete,createtime,modify_time from offline_portfolio where %@",where];
     
     
     [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
     
-    [iSalesDB jk_query:sqlQuery completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+    
+    sqlite3 *db = [iSalesDB get_db];
+    
+    NSDictionary *queryDic = [iSalesDB jk_query:sqlQuery db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
         
         NSMutableDictionary *item = [NSMutableDictionary dictionary];
         
@@ -10746,6 +10750,11 @@
         NSString *create_time = [self textAtColumn:14 statement:stmt];
         NSString *modify_time = [self textAtColumn:15 statement:stmt];
         
+        NSString *price_null = [self textAtColumn:9 statement:stmt];
+        if ([price_null isEqualToString:@"null"]) {
+            price = [[self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db] doubleValue];
+        }
+        
         [item setValue:[NSNumber numberWithInteger:_id] forKey:@"_id"];
         [item setValue:[NSNumber numberWithInteger:product_id] forKey:@"product_id"];
         [item setValue:[NSNumber numberWithInteger:item_id] forKey:@"item_id"];
@@ -10770,12 +10779,15 @@
         [ret setObject:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
         [ret setObject:[NSNumber numberWithInteger:*count] forKey:@"count"];
         
-    } failure:^(NSMutableDictionary *container, NSString *err_msg) {
-        
-        [ret setObject:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
-        
     }];
     
+    [iSalesDB close_db:db];
+    
+    if ([[queryDic objectForKey:@"result"] integerValue] == RESULT_FALSE) {
+        [ret setObject:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
+    }
+    
+    
     return ret;
 }
 
@@ -10797,7 +10809,7 @@
         
     }
     
-    NSString *sqlQuery =[NSString stringWithFormat:@"select _id,tearsheets_id,pdf_path,create_user,tear_note,tear_name,model_info,createtime from offline_pdf where %@",where];
+    NSString *sqlQuery =[NSString stringWithFormat:@"select _id,tearsheets_id,pdf_path,create_user,tear_note,tear_name,model_info,createtime,modify_time from offline_pdf where %@",where];
     
     
     [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
@@ -10814,6 +10826,7 @@
         NSString *tear_name = [self textAtColumn:5 statement:stmt];
         NSString *model_info = [self textAtColumn:6 statement:stmt];
         NSString *createtime = [self textAtColumn:7 statement:stmt];
+        NSString *modifytime = [self textAtColumn:8 statement:stmt];
         
         [item setObject:[NSNumber numberWithInteger:_id] forKey:@"_id"];
         [item setObject:[NSNumber numberWithInteger:tearsheets_id] forKey:@"tearsheets_id"];
@@ -10823,7 +10836,7 @@
         [item setObject:tear_name forKey:@"tear_name"];
         [item setObject:model_info forKey:@"model_info"];
         [item setObject:createtime forKey:@"createtime"];
-
+        [item setObject:modifytime forKey:@"modifytime"];
 
         [ret setObject:item forKey:[NSString stringWithFormat:@"item_%ld",(*count)++]];
         [ret setObject:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];