Commit 51a716f0 authored by Sandy's avatar Sandy

优化许可证答案的提交

parent fa4413dc
......@@ -522,9 +522,6 @@ GXFBottomViewDelegate>
ICRAnswer *answer = answerArr[i];
//找到数据表中的附件
ICRDatabaseFetchBlock fetchBlk = ^FMResultSet *(FMDatabase *db) {
// NSString *sql = [NSString stringWithFormat:@"SELECT *FROM %@ WHERE %@ IN %@ ORDER BY %@ ",[ICRPostAttachment TableName],@"questionUuid",[IBTModel ValuePlaceholdersWithCount:muArr.count],@"addTime"];
// return [db executeQuery:sql withArgumentsInArray:muArr];
//
NSString *sql = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE %@=? AND %@=? AND %@=? ORDER BY %@",[ICRPostAttachment TableName],@"questionUuid",@"plan_uuid",@"store_uuid",@"addTime"];
return [db executeQuery:sql,answer.questionUuid,answer.plan_uuid,answer.store_uuid];
};
......
......@@ -99,6 +99,7 @@ static NSString *headerProblemItemID = @"headerItem";
// Do any additional setup after loading the view.
self.title = @"许可证结果";
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doHttp:) name:@"doHttp" object:nil];
[self initSubViews];
}
- (void)viewWillAppear:(BOOL)animated
......@@ -512,10 +513,6 @@ static NSString *headerProblemItemID = @"headerItem";
} else {
[self PopViewControllerAnimated:YES];
}
// [self PopViewControllerAnimated:YES];
// GTOLicenceListViewController *listVC = [[GTOLicenceListViewController alloc]init];
// [self PushViewController:listVC animated:YES];
} else {
[IBTLoadingView showTextOnly:data[@"message"] inView:self.view];
}
......@@ -550,8 +547,6 @@ static NSString *headerProblemItemID = @"headerItem";
} else {
[self PopViewControllerAnimated:YES];
}
// GTOLicenceListViewController *listVC = [[GTOLicenceListViewController alloc]init];
// [self PushViewController:listVC animated:YES];
} else {
[IBTLoadingView showTextOnly:data[@"message"] inView:self.view];
}
......@@ -559,7 +554,6 @@ static NSString *headerProblemItemID = @"headerItem";
};
void (^failure)(id) = ^(id data) {
[IBTLoadingView hideHUDWithText:nil];
// CLog(@"%@", data);
};
[httpCtrl doSubmitLicenceResultWithData:[licenceR dictForCommit] success:success failure:failure];
......@@ -631,24 +625,147 @@ static NSString *headerProblemItemID = @"headerItem";
- (void)upLoadFlieWithAction:(NSString *)action
{
NSInteger counts = 0;
__block NSInteger counts = 0;
__block NSInteger totalCounts = _d_licence.arrDisplayResults.count;
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
hud.labelText = [NSString stringWithFormat:@"已上传%lu%%", counts * 100 / _d_licence.arrDisplayResults.count];
hud.labelText = [NSString stringWithFormat:@"已上传%lu%%", counts * 100 / totalCounts];
for (int count = 0; count < _d_licence.arrDisplayResults.count; count++) {
GTODisplayResult *displayR = [GTODisplayResult DBObject];
[displayR praseFromJsonDict:_d_licence.arrDisplayResults[count]];
for (int ansCount = 0; ansCount < displayR.arrAnswers.count; ansCount++) {
// if(count ==0 && ansCount==0){
// [IBTLoadingView showProgressLabel:@"正在上传图片"];
// }
GTOAnswer *answer = [GTOAnswer DBObject];
[answer praseFromJsonDict:displayR.arrAnswers[ansCount]];
BOOL isFinish = NO;
if ((ansCount == displayR.arrAnswers.count - 1) && (count == _d_licence.arrDisplayResults.count - 1)) {
isFinish = YES;
}
[self everyProblemUpLoadPhotoWithAnswer:answer isFinishedUpload:isFinish action:action index:count count:counts allCounts:_d_licence.arrDisplayResults.count hud:hud];
//上传附件
WS(weakSelf);
ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
[dbCtrl runFetchForClass:[ICRPostAttachment class] fetchBlock:^FMResultSet *(FMDatabase *db)
{
NSString *sql = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE %@=? AND %@=? ORDER BY %@", [ICRPostAttachment TableName], @"questionUuid", @"licenceUuid", @"addTime"];
return [db executeQuery:sql, answer.questionUuid, answer.licenceUuid];
} fetchResultsBlock:^(NSArray *fetchObjects) {
__strong __typeof(weakSelf) strongSelf = weakSelf;
if (!fetchObjects) {
if (!isFinish) {
return;
} else {
if ([action isEqualToString:@"save"]) {
[self httpSaveLicenceResult];
} else {
[self httpSubmitLicenceResult];
}
return;
}
}
if (fetchObjects.count > 0) {
if (!_d_arrPostAttachments) {
strongSelf.d_arrPostAttachments = [@[] mutableCopy];
} else {
[strongSelf.d_arrPostAttachments removeAllObjects];
}
NSMutableArray *delArr = [@[] mutableCopy];
NSMutableArray *delArrPostAttachments = [@[] mutableCopy];
NSMutableArray *addArrPostAttachments = [@[] mutableCopy];
for (ICRPostAttachment *postAttachment in fetchObjects) {
if (postAttachment.is_delete) {
[delArr addObject:postAttachment.uuid];
}
if (postAttachment.is_localPhoto) {
[addArrPostAttachments addObject:postAttachment];
[strongSelf.d_arrPostAttachments addObject:postAttachment];
} else if (!postAttachment.is_localPhoto && postAttachment.is_delete) {
[delArrPostAttachments addObject:postAttachment];
[strongSelf.d_arrPostAttachments addObject:postAttachment];
} else {
}
}
NSString *delStr = [delArr componentsJoinedByString:@";"];
if (delStr.length <= 0) {
delStr = @"";
}
if (addArrPostAttachments.count > 0 || delArrPostAttachments.count > 0) {
ICRPostAttachment *postAttachment = _d_arrPostAttachments[0];
ICRHTTPController *httpC = [ICRHTTPController sharedController];
if (delArrPostAttachments.count > 0) {
[httpC deleteAttachments:delStr success:^(id data) {
if ([data[@"success"] integerValue] == 1) {
[strongSelf localDeleteOneAnswerPhotos:answer];
if (!isFinish) {
return;
} else {
[IBTLoadingView hideHUDWithText:nil];
if ([action isEqualToString:@"save"]) {
[self httpSaveLicenceResult];
} else {
[self httpSubmitLicenceResult];
}
}
} else {
[IBTLoadingView hideHUDWithText:data[@"message"]];
}
} failure:^(id data) {
[IBTLoadingView hideHUDWithText:@"上传删除的图片出错啦! 请重新上传。"];
}];
}
//添加附件
if (addArrPostAttachments.count > 0) {
[httpC multiPartUploadWithEntityType:postAttachment.entityType
entityUuid:postAttachment.entityUuid
arrayPostAttachments:addArrPostAttachments
success:^(id data) {
if ([data[@"success"] integerValue] == 1) {
counts++;
CLog(@"------>count = %d", count);
if (!isFinish) {
[strongSelf localDeleteOneAnswerPhotos:answer];
hud.labelText = [NSString stringWithFormat:@"已上传%lu%%", counts * 100 / _d_licence.arrDisplayResults.count];
if (counts == totalCounts) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"doHttp" object:action];
[IBTLoadingView hideHUDWithText:nil];
[hud removeFromSuperview];
}
return;
} else {
}
} else {
[IBTLoadingView hideHUDWithText:data[@"message"]];
}
}
failure:^(id data) {
[IBTLoadingView hideHUDWithText:@"上传图片出错啦! 请重新上传。"];
}];
}
} else {
if (!isFinish) {
return;
} else {
if ([action isEqualToString:@"save"]) {
[self httpSaveLicenceResult];
} else {
[self httpSubmitLicenceResult];
}
}
}
}
}];
// [self everyProblemUpLoadPhotoWithAnswer:answer isFinishedUpload:isFinish action:action index:count count:counts allCounts:_d_licence.arrDisplayResults.count hud:hud];
}
}
}
......@@ -705,6 +822,7 @@ static NSString *headerProblemItemID = @"headerItem";
[delArrPostAttachments addObject:postAttachment];
[strongSelf.d_arrPostAttachments addObject:postAttachment];
} else {
}
}
NSString *delStr = [delArr componentsJoinedByString:@";"];
......@@ -948,6 +1066,15 @@ static NSString *headerProblemItemID = @"headerItem";
}
}
}
- (void)doHttp:(NSNotification *)note {
NSString *action = note.object;
if ([action isEqualToString:@"save"]) {
[self httpSaveLicenceResult];
} else {
[self httpSubmitLicenceResult];
}
}
#pragma button Action
- (void)seeRepairClicked
{
......
......@@ -807,6 +807,7 @@ didVideoPickedWithURL:(NSURL *)videoUrl {
[licence.state isEqualToString:@"initial"] ||
[licence.state isEqualToString:@"askforapprove"]) {
[IBTLoadingView hideHUDWithText:@"有未提交或待审批的许可证,请处理完成后重试"];
return;
}
}
void(^succ)(id) = ^(id data) {
......@@ -820,7 +821,6 @@ didVideoPickedWithURL:(NSURL *)videoUrl {
[IBTLoadingView hideHUDWithText:data[@"message"]];
}
};
void(^fail)(id) = ^(id data) {
......
......@@ -91,8 +91,8 @@
//#define HTTP_REST_API_BASE_URL @"http://139.196.39.77:8080/total-server/rest"
//开发环境
#define HTTP_LOCAL_BASE_URL @"http://139.196.195.30:8093"
#define HTTP_REST_API_BASE_URL @"http://139.196.195.30:8093/total-server/rest"
//#define HTTP_LOCAL_BASE_URL @"http://139.196.195.30:8093"
//#define HTTP_REST_API_BASE_URL @"http://139.196.195.30:8093/total-server/rest"
#define HTTP_WEATHER_URL @"http://apis.baidu.com/heweather/weather/free"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment