ICRHTTPController.m 110 KB
Newer Older
mei's avatar
mei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
//
//  ICRHTTPController.m
//  XFFruit
//
//  Created by Xummer on 3/26/15.
//  Copyright (c) 2015 Xummer. All rights reserved.
//

#import "ICRHTTPController.h"
#import "ICRUserUtil.h"
#import "AFNetworking.h"
#import "Base64.h"
#import "AFNetworkActivityIndicatorManager.h"
#import "NSDate+FormatterAdditions.h"

#import "IBTModel.h"
#import "ICRAttachment.h"
#import "ICRAnnouncement.h"
#import "ICRStoreResult.h"

#define MAX_CONCURRENCY_UPLOAD      1
#define MAX_CONCURRENCY_DOWNLOAD    3

#define ERROR_PARAMETER             @"Error: Bad Parameter(s)"

NSString * const ICRHTTPErrorDomain = @"ICRHTTPErrorDomain";

typedef NS_ENUM(NSUInteger, ICRHTTPAction) {
    kICRHTTP_Dummy = 0,
    // User
    kICRHTTP_UserLogin,
    kICRHTTP_UserResetPassword,
    
    // Data
    kICRHTTP_StoreQuery,
    kICRHTTP_CurrentOrg,
    
    // Board
    kICRHTTP_BoardQuery,
    kICRHTTP_ReadBoard,
    
    // Patrol
    kICRHTTP_PatrolQuery,
    kICRHTTP_AnswerStoreResult,
    kICRHTTP_PatrolAnswer,
    kICRHTTP_PatrolOneAnswer,
    
    // Task
    kICRHTTP_MyTaskQuery,
    kICRHTTP_TaskNew,
    kICRHTTP_TaskResult,
    
    // Signup
    kICRHTTP_SignUp,
    
    // Attachment
    kICRHTTP_AttachmentAdd,
    kICRHTTP_AttachmentList,
    kICRHTTP_AttachmentDownload,
    kICRHTTP_AttachmentAddDirect,
    kICRHTTP_AttachmentDownloadDirect,
    
    // Version
    kICRHTTP_VersionFetch,
    
    //Person
67 68
    kICRHTTP_PersonQuery,
    
陈俊俊's avatar
陈俊俊 committed
69 70 71
    //行情
    XFFHttp_SurveySave,
    XFFHttp_QuerySurvey,
n22's avatar
n22 committed
72
    XFFHttp_GetSurvey,
n22's avatar
n22 committed
73
    XFFHttp_GetProduct,
陈俊俊's avatar
陈俊俊 committed
74 75 76 77
    XFFHttp_GetUser,
    XFFHttp_SurveyFinish,
    //行情反馈图片
    XFFHttp_ResultChart,
陈俊俊's avatar
陈俊俊 committed
78
    XFFHttp_GetResults,
陈俊俊's avatar
陈俊俊 committed
79 80 81
    //附件下载
    XFFHttp_Attachment,
    
陈俊俊's avatar
陈俊俊 committed
82
    //供应商
n22's avatar
n22 committed
83 84
    XFFHttp_GetVendor,
    //仓库
freecui's avatar
freecui committed
85
    XFFHttp_GetWarehouse,
86 87
    //用户仓库表
    XFFHttp_downloadUserWarehouse,
陈俊俊's avatar
陈俊俊 committed
88 89
    //科目账单
    XFFHttp_GetAccounttitle,
freecui's avatar
freecui committed
90

freecui's avatar
freecui committed
91 92 93 94
    //商品单位
    XFFHttp_GetProductunit,
    //加工单
    XFFHttp_QueryProcess,
freecui's avatar
freecui committed
95
    XFFHttp_GetProcess,
freecui's avatar
freecui committed
96 97 98
    XFFHttp_SaveProcess,
    XFFHttp_FinishProcess,
    XFFHttp_AbortProcess,
zhu's avatar
zhu committed
99
    //采购通知单
zhu's avatar
zhu committed
100 101 102 103 104 105 106 107
    XFFHttp_savePurchaseNotice,
    XFFHttp_getPurchaseNoticeList,
    XFFHttp_getPurchaseNoticeDetailed,
    XFFHttp_saveAndSubmitPurchaseNotice,
    XFFHttp_ComitPurchaseNotice,
    XFFHttp_acceptPurchaseNotice,
    XFFHttp_finishPurchaseNotice,
    XFFHttp_getPurchaseNoticeRecod,
zhu's avatar
zhu committed
108
    
freecui's avatar
freecui committed
109

陈俊俊's avatar
陈俊俊 committed
110 111 112 113
    //采购单
    XFFHttp_PurchaseSave,
    XFFHttp_QueryPurchase,
    XFFHttp_GetPurchaseDetail,
陈俊俊's avatar
陈俊俊 committed
114 115 116 117
    XFFHttp_DealByActionPurchase,
    
    //发运单
    XFFHttp_TransportSave,
陈俊俊's avatar
陈俊俊 committed
118
    XFFHttp_TransportSaveAndSubmit,
陈俊俊's avatar
陈俊俊 committed
119 120 121
    XFFHttp_QueryTransport,
    XFFHttp_GetTransportDetail,
    XFFHttp_EndTransport,
陈俊俊's avatar
陈俊俊 committed
122 123 124 125 126 127 128 129 130
    XFFHttp_AbortTransport,
    
    //转运单
    
    XFFHttp_QueryTransfer,
    XFFHTTP_TransferSave,
    XFFHttp_GetTransferDetail,
    XFFHttp_EndTransfer,
    XFFHttp_AbortTransfer,
陈俊俊's avatar
陈俊俊 committed
131 132 133
    //收货单
    XFFHttp_SaveRctinfo,
    XFFHttp_SaveReceipt,
zhu's avatar
zhu committed
134
   //版本更新
陈俊俊's avatar
陈俊俊 committed
135 136 137
    XFFHttp_getVersionId,
    //报表首页,数据罗盘
    XFFHttp_QueryHomepage,
138
    XFFHttp_QueryLowerOrgs,
陈俊俊's avatar
陈俊俊 committed
139
    
mei's avatar
mei committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
};

static NSString * const ICRHTTPInterface[] = {
    [ kICRHTTP_Dummy ]                      = @"",
    
    // User
    [ kICRHTTP_UserLogin ]                  = @"user/login",
    [ kICRHTTP_UserResetPassword ]          = @"user/change_password",
    
    // Data
    [ kICRHTTP_StoreQuery ]                 = @"mdata/store/download",
    [ kICRHTTP_CurrentOrg ]                 = @"data/organization/currentOrg",
    
    // Board
    [ kICRHTTP_BoardQuery ]                 = @"affiche/download",
    [ kICRHTTP_ReadBoard ]                  = @"board/read",
    

   
    
    // Patrol
    [ kICRHTTP_PatrolQuery ]                = @"patrol/plan/download",
    [ kICRHTTP_AnswerStoreResult ]          = @"patrol/plan/get_store_result",
    [ kICRHTTP_PatrolAnswer ]               = @"patrol/plan/submit_result",
    [ kICRHTTP_PatrolOneAnswer ]            = @"patrol/oneAnswer",
    
    // Task
    [ kICRHTTP_MyTaskQuery ]                  = @"task/task/downloadForProcessor",
    [ kICRHTTP_TaskNew ]                    = @"task/task/submit",
    [ kICRHTTP_TaskResult ]                 = @"task/task",
    
    // Signup
    [ kICRHTTP_SignUp ]                     = @"signin",
    
    // Attachment
    [ kICRHTTP_AttachmentAdd ]              = @"attachment/upload",
    [ kICRHTTP_AttachmentList ]             = @"attachment/list",
    [ kICRHTTP_AttachmentDownload ]         = @"attachment/download",
    [ kICRHTTP_AttachmentAddDirect ]        = @"attachment/addDirect",
    [ kICRHTTP_AttachmentDownloadDirect ]   = @"attachment/downloadDirect",
    
    // Version
    [ kICRHTTP_VersionFetch ]               = @"version/fetch",
    
    //Person
    [kICRHTTP_PersonQuery]                  =  @"user/download",
186
    //行情调研
陈俊俊's avatar
陈俊俊 committed
187 188
    [XFFHttp_SurveySave]                    = @"survey/save_survey",
    [XFFHttp_QuerySurvey]                   = @"survey/query_survey",
n22's avatar
n22 committed
189
    [XFFHttp_GetSurvey]                     = @"survey/get_survey",
n22's avatar
n22 committed
190
    [XFFHttp_GetProduct]                    = @"mdata/product/download",
陈俊俊's avatar
陈俊俊 committed
191 192 193 194
    [XFFHttp_GetUser]                       = @"user/download",
    [XFFHttp_SurveyFinish]                  = @"survey/finish",
    //行情反馈生成图片
    [XFFHttp_ResultChart]                   = @"survey/resultchart",
n22's avatar
n22 committed
195
    [XFFHttp_GetResults]                    = @"survey/get_results",
陈俊俊's avatar
陈俊俊 committed
196 197
    [XFFHttp_Attachment]                    = @"attachment/download",
    
n22's avatar
n22 committed
198
    //供应商
n22's avatar
n22 committed
199
    [XFFHttp_GetVendor]                     = @"data/vendor/download",
n22's avatar
n22 committed
200 201
    //仓库
    [XFFHttp_GetWarehouse]                  = @"data/warehouse/download",
202 203
    [XFFHttp_downloadUserWarehouse]         = @"data/warehouse/downloadUserWarehouse",

陈俊俊's avatar
陈俊俊 committed
204 205 206
    //科目账单
    [XFFHttp_GetAccounttitle]               = @"data/accounttitle/download",
    
freecui's avatar
freecui committed
207
    //商品单位
陈俊俊's avatar
陈俊俊 committed
208
    [XFFHttp_GetProductunit]                = @"mdata/productunit/download",
freecui's avatar
freecui committed
209
    //加工单
freecui's avatar
freecui committed
210 211 212 213 214
    [XFFHttp_QueryProcess ]                 = @"process/query",
    [XFFHttp_GetProcess ]                   = @"process/get",
    [XFFHttp_SaveProcess]                   = @"process/save",
    [XFFHttp_FinishProcess]                 = @"process/finish",
    [XFFHttp_AbortProcess]                  = @"process/abort",
zhu's avatar
zhu committed
215
    //采购通知单
陈俊俊's avatar
陈俊俊 committed
216
    [XFFHttp_savePurchaseNotice]            = @"purchase/notice/save",
zhu's avatar
zhu committed
217
    [XFFHttp_getPurchaseNoticeList]         = @"purchase/notice/query",
陈俊俊's avatar
陈俊俊 committed
218 219 220
    [XFFHttp_getPurchaseNoticeDetailed]     = @"purchase/notice/get",
    [XFFHttp_saveAndSubmitPurchaseNotice]   = @"purchase/notice/saveandsubmit",
    [XFFHttp_ComitPurchaseNotice]           = @"purchase/notice/submit/",
陈俊俊's avatar
陈俊俊 committed
221 222
    [XFFHttp_acceptPurchaseNotice]          = @"purchase/notice/accept",
    [XFFHttp_finishPurchaseNotice]          = @"purchase/notice/finish",
zhu's avatar
zhu committed
223
    
zhu's avatar
zhu committed
224
    [XFFHttp_getPurchaseNoticeRecod]        = @"purchase/trace/get",
zhu's avatar
zhu committed
225
    
freecui's avatar
freecui committed
226

陈俊俊's avatar
陈俊俊 committed
227 228 229 230
    //采购单
    [XFFHttp_PurchaseSave]                  = @"purchase/bill/save",
    [XFFHttp_QueryPurchase]                 = @"purchase/bill/query",
    [XFFHttp_GetPurchaseDetail]             = @"purchase/bill/get",
陈俊俊's avatar
陈俊俊 committed
231
    [XFFHttp_DealByActionPurchase]          = @"purchase/bill/action",
freecui's avatar
freecui committed
232

陈俊俊's avatar
陈俊俊 committed
233 234 235
    
    //发运单
    [XFFHttp_TransportSave]                 = @"transport/save_transport",
陈俊俊's avatar
陈俊俊 committed
236
    [XFFHttp_TransportSaveAndSubmit]        = @"transport/saveandsubmit_transport",
陈俊俊's avatar
陈俊俊 committed
237 238 239 240
    [XFFHttp_QueryTransport]                = @"transport/query_transport",
    [XFFHttp_GetTransportDetail]            = @"transport/get_transport",
    [XFFHttp_EndTransport]                  = @"transport/finish",
    [XFFHttp_AbortTransport]                = @"transport/abort",
陈俊俊's avatar
陈俊俊 committed
241
    
陈俊俊's avatar
陈俊俊 committed
242
    //转运单
陈俊俊's avatar
陈俊俊 committed
243 244 245
    [XFFHTTP_TransferSave]                  = @"transfer/save_transfer",
    [XFFHttp_QueryTransfer]                 = @"transfer/query_transfer",
    [XFFHttp_GetTransferDetail]             = @"transfer/get_transfer",
陈俊俊's avatar
陈俊俊 committed
246 247 248
    [XFFHttp_EndTransfer]                   = @"transfer/finish",
    [XFFHttp_AbortTransfer]                 = @"transfer/abort",
    //收货
陈俊俊's avatar
陈俊俊 committed
249 250 251 252 253
    [XFFHttp_SaveRctinfo]                   = @"transfer/save_rctinfo",
    [XFFHttp_SaveReceipt]                   = @"transfer/receipt",
    //版本升级
    [XFFHttp_getVersionId]                  = @"ipapk",
    //报表
254
    [XFFHttp_QueryHomepage]                 = @"salesdata/query",
255
    [XFFHttp_QueryLowerOrgs]                = @"organization/queryLowerOrgs",
陈俊俊's avatar
陈俊俊 committed
256
    
zhu's avatar
zhu committed
257

mei's avatar
mei committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
};

static NSString * const ICRAttachmentTypeValue[] = {
    [ kAttachmentBoard ]                    = @"board",
    [ kAttachmentAnswer ]                   = @"answer",
    [ kAttachmentTask ]                     = @"task",
};

@interface ICRHTTPController ()
/**
 *  The upload operation queue on which upload request operations are scheduled and run.
 */
@property (nonatomic, strong) NSOperationQueue *uploadOperationQueue;

/**
 *  The download operation queue on which download request operations are scheduled and run.
 */
@property (nonatomic, strong) NSOperationQueue *downloadOperationQueue;

@end

@implementation ICRHTTPController

#pragma mark - Class Method

+ (instancetype)sharedController {
    static ICRHTTPController *_sharedController = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedController = [[self alloc] init];
    });
    
    return _sharedController;
}

+ (NSString *)UrlForPluginHTTPAction:(ICRHTTPAction)action {
    return [HTTP_REST_API_BASE_URL stringByAppendingFormat:@"/%@", ICRHTTPInterface[ action ]];
}

+ (NSError *)ErrorWithMsg:(NSString *)nsErrorMsg code:(NSInteger)uiCode {
    NSDictionary *userInfo =
    nsErrorMsg ? @{ NSLocalizedFailureReasonErrorKey : nsErrorMsg } : nil;
    
    NSError *error =
    [[NSError alloc] initWithDomain:ICRHTTPErrorDomain
                               code:uiCode userInfo:userInfo];
    
    return error;
}

+ (id)GetErrorMsgFromOperation:(AFHTTPRequestOperation *)operation error:(NSError *)error
{
    id data = operation.responseObject;
    if ([data isKindOfClass:[NSDictionary class]]) {
        NSString *errorMsg = data[ @"message" ];
        return [[self class] ErrorWithMsg:errorMsg code:[[operation response] statusCode]];
    }
    else {
        return error;
    }
}


#pragma mark - Life Cycle
- (id)init {
    self = [super init];
    if (!self) {
        return nil;
    }
    
    [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
    
    self.uploadOperationQueue = [[NSOperationQueue alloc] init];
    [self.uploadOperationQueue setMaxConcurrentOperationCount:MAX_CONCURRENCY_UPLOAD];
    
    self.downloadOperationQueue = [[NSOperationQueue alloc] init];
    [self.downloadOperationQueue setMaxConcurrentOperationCount:MAX_CONCURRENCY_DOWNLOAD];
    
    return self;
}

#pragma mark - Private Method
- (AFJSONRequestSerializer *)requestNeedToken:(BOOL)bIsNeedToken
                               acceptTypeJson:(BOOL)bAcceptJson
                                      failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))fail
{
    AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];
    ICRUserUtil *user = [ICRUserUtil sharedInstance];
    if (bIsNeedToken) {
        if ([user.token length] > 0) {
            if (!requestSerializer.HTTPRequestHeaders[ @"token" ]) {
                [requestSerializer setValue:user.token forHTTPHeaderField:@"token"];
            }
        }
        else {
            NSDictionary *userInfo = @{ NSLocalizedFailureReasonErrorKey : @"The authorization must not be nil." };
            NSError *error = [[NSError alloc] initWithDomain:ICRHTTPErrorDomain code:0 userInfo:userInfo];
            fail(nil, error);
        }
    }
    
    if (bAcceptJson) {
        if (!requestSerializer.HTTPRequestHeaders[ @"Accept" ]) {
            [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        }
    }
陈俊俊's avatar
陈俊俊 committed
364

mei's avatar
mei committed
365
    [requestSerializer setValue:@"application/json;charset=utf-8" forHTTPHeaderField: @"Content-Type"];
陈俊俊's avatar
陈俊俊 committed
366

mei's avatar
mei committed
367 368 369 370 371
    //请求头添加enterprise参数
    if(user.orgId != NULL)
    {
        [requestSerializer setValue:user.orgId forHTTPHeaderField:@"enterprise"];
    }
n22's avatar
n22 committed
372
    [requestSerializer setValue:user.authenticode forHTTPHeaderField:@"authorization"];
mei's avatar
mei committed
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
   
    return requestSerializer;
}

- (void)GET:(NSString *)urlStr
 parameters:(id)parameters
  needToken:(BOOL)bIsNeedToken
acceptTypeJson:(BOOL)bAcceptJson
    success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))succ
    failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))fail
{
    AFJSONRequestSerializer *requestSerializer =
    [self requestNeedToken:bIsNeedToken acceptTypeJson:bAcceptJson failure:fail];
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        succ(operation, responseObject);
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        fail(operation, [[self class] GetErrorMsgFromOperation:operation error:error]);
    };
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer = requestSerializer;
    NSLog(@"headers=======>>>>>>>>>%@",[manager.requestSerializer HTTPRequestHeaders]);
    // The request add in operation

 
    // The request add in operation
    [manager GET:urlStr
      parameters:parameters
         success:success
         failure:failure];
}

- (void)POST:(NSString *)urlStr
  parameters:(id)parameters
   needToken:(BOOL)bIsNeedToken
acceptTypeJson:(BOOL)bAcceptJson
     success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))succ
     failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))fail
{
    AFJSONRequestSerializer *requestSerializer =
    [self requestNeedToken:bIsNeedToken acceptTypeJson:bAcceptJson failure:fail];
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        succ(operation, responseObject);
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        fail(operation, [[self class] GetErrorMsgFromOperation:operation error:error]);
    };
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.requestSerializer = requestSerializer;
陈俊俊's avatar
陈俊俊 committed
428 429 430
   
    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];
    
mei's avatar
mei committed
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
       [manager POST:urlStr
       parameters:parameters
          success:success
          failure:failure];
}

- (void)PATCH:(NSString *)urlStr
   parameters:(id)parameters
    needToken:(BOOL)bIsNeedToken
acceptTypeJson:(BOOL)bAcceptJson
      success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))succ
      failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))fail
{
    AFJSONRequestSerializer *requestSerializer =
    [self requestNeedToken:bIsNeedToken acceptTypeJson:bAcceptJson failure:fail];
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        succ(operation, responseObject);
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        fail(operation, [[self class] GetErrorMsgFromOperation:operation error:error]);
    };
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer = requestSerializer;
  
    
    // The request add in operation
    [manager PATCH:urlStr
        parameters:parameters
           success:success
           failure:failure];
}

- (void)DELETE:(NSString *)urlStr
    parameters:(id)parameters
     needToken:(BOOL)bIsNeedToken
acceptTypeJson:(BOOL)bAcceptJson
       success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))succ
       failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))fail
{
    AFJSONRequestSerializer *requestSerializer =
    [self requestNeedToken:bIsNeedToken acceptTypeJson:bAcceptJson failure:fail];
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        succ(operation, responseObject);
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        fail(operation, [[self class] GetErrorMsgFromOperation:operation error:error]);
    };
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer = requestSerializer;
    
    // The request add in operation
    [manager DELETE:urlStr
         parameters:parameters
            success:success
            failure:failure];
}

#pragma mark - User
- (void)doLoginWithUserName:(NSString *)nsUserName
                   password:(NSString *)nsPassword
               registerCode:(NSString *)nsRegisterCode
                    success:(void (^)(id data))succ
                    failure:(void (^)(id data))fail
{
    if (!nsUserName || !nsPassword || !nsRegisterCode) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@",responseObject);
        
        id dictResult = responseObject[ @"data" ];
        if (dictResult) {
            
            ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
            userUtil.userName = nsUserName;
            userUtil.password = nsPassword;
            userUtil.registerCode = nsRegisterCode;
陈俊俊's avatar
陈俊俊 committed
518 519 520 521 522 523
            userUtil.displayName = dictResult[ @"user_name" ];
            userUtil.userCode =dictResult[ @"user_code" ];
            userUtil.userId = dictResult[ @"user_uuid" ];
            userUtil.orgCode = dictResult[ @"enterprise_code" ];
            userUtil.orgName = dictResult[ @"enterprise_name" ];
            userUtil.orgId = dictResult[ @"enterprise_uuid" ];
n22's avatar
n22 committed
524
            userUtil.authenticode = dictResult[@"authenticode"];
freecui's avatar
freecui committed
525
            userUtil.permissions = dictResult[@"permissions"];
526 527 528
            userUtil.org_code = dictResult[ @"org_code" ];
            userUtil.org_name = dictResult[ @"org_name" ];
            userUtil.org_uuid = dictResult[ @"org_uuid" ];
529
            userUtil.belongOrgPath = dictResult[ @"belongOrgPath" ];
管鹏飞's avatar
管鹏飞 committed
530 531
            userUtil.password = nsPassword;
            userUtil.isLogout = NO;
mei's avatar
mei committed
532 533 534 535 536 537 538
            [userUtil saveArchive];
            if (succ) {
                succ( dictResult );
            }
        }
        else {
            if (fail) {
freecui's avatar
freecui committed
539
                fail( responseObject[@"message"] );
mei's avatar
mei committed
540 541 542 543 544 545 546 547 548 549
            }
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@",error);
        if (fail) {
            fail( error );
        }
    };
管鹏飞's avatar
管鹏飞 committed
550
     // NSString *nsPassword = [self.m_containerView.m_passwordTextF.text uppercaseMD5String];
mei's avatar
mei committed
551
    NSDictionary *dictParametes =
管鹏飞's avatar
管鹏飞 committed
552
    @{ @"password" : [nsPassword uppercaseMD5String],
mei's avatar
mei committed
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
       @"authenticode" : nsRegisterCode,
      };
    
    NSLog(@"%@",dictParametes);
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_UserLogin] stringByAppendingFormat:@"/%@", nsUserName];
    [self POST:urlStr
    parameters:dictParametes
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doChangePassword:(NSString *)nsPassword
             newPassword:(NSString *)nsNewPassword
                 success:(void (^)(id data))succ
                 failure:(void (^)(id data))fail
{
    if (!nsPassword || !nsNewPassword) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
//http://.../XFFruit-server/rest/user/change_password/{user_uuid}?time={time}&operator.id={operatorId}&operator.operName={operatorName}&enterprise={enterprise}
//    请求参数:
    
    NSDictionary *dictParametes =
    @{ @"oldPassword" : nsPassword,
       @"newPassword" : nsNewPassword,
       };
    
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_UserResetPassword] stringByAppendingFormat:@"/%@?time=%@&operator.id=%@&operator.operName=%@&enterprise=%@",userUtil.userId,currentTime,userUtil.userCode,userUtil.displayName,userUtil.orgId];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//对url进行utf-8编码,否则不合法
    CLog(@"%@",encodeUrlStr);
    [self POST:encodeUrlStr
    parameters:dictParametes
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}


#pragma mark - Data
- (void)doGetStoreListFromUpdateTime:(NSTimeInterval)updateTime
                            position:(NSUInteger)uiPosition
                                size:(NSUInteger)uiSize
                             success:(void (^)(id data))succ
                             failure:(void (^)(id data))fail
{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntities:responseObject[ @"data" ][ @"records" ]
                        objectClass:NSClassFromString( @"ICRStore" )
                        deleteLocal:YES
                         handleData:NULL
                         complete:complete
                             fail:fail];
        }
        else {
            if (fail) {
                fail( nil );
            }
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_StoreQuery] stringByAppendingFormat:@"?start_date=%@&page_number=%@&page_size=%@", [[NSDate dateWithTimeIntervalSince1970:updateTime] httpParameterString],@(uiPosition),@(uiSize)];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:NULL
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doGetCurrentOrgWithSuccess:(void (^)(id data))succ
                           failure:(void (^)(id data))fail
{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:kICRHTTP_StoreQuery];
    [self GET:urlStr
   parameters:nil
    needToken:YES
acceptTypeJson:YES
      success:success
      failure:failure];
}

- (void)doGetPersonListFromUpdateTime:(NSString *)updateTime
                           position:(NSUInteger)uiPosition
                               size:(NSUInteger)uiSize
                            success:(void (^)(id data))succ
                            failure:(void (^)(id data))fail
{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntities:responseObject[ @"data" ][ @"records" ]
                        objectClass:NSClassFromString( @"ICRPerson" )
                        deleteLocal:YES
                         handleData:NULL
                           complete:complete
                               fail:fail];
        }
        else {
            if (fail) {
                fail( nil );
            }
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    //http://.../XFFruit-server/rest/user/download?start_date=? &page_number=?&page_size=?
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_PersonQuery] stringByAppendingFormat:@"?start_date=%@&page_number=%@&page_size=%@",updateTime ? : [[NSDate dateWithTimeIntervalSince1970:0] httpParameterString],@( uiPosition ),@( uiSize )];
    NSString * encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"=======>>>>>>>>>>>>>>>%@",encodeUrlStr);
    [self POST:encodeUrlStr
    parameters:NULL
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

#pragma mark - Board
- (void)doGetBoardListFromUpdateTime:(NSString *)updateTime
                            position:(NSUInteger)uiPosition
                                size:(NSUInteger)uiSize
                                type:(ICRAnnouncementType)eType
                         deleteLocal:(BOOL)bDeleteLocal
                             success:(void (^)(id data))succ
                             failure:(void (^)(id data))fail
{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            void(^dataHandle)(id<IBTDatabaseObject>) = ^(id<IBTDatabaseObject> model) {
                ICRAnnouncement *ann = model;
                ann.priority = eType;
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntities:responseObject[ @"data" ][ @"records" ]
                        objectClass:NSClassFromString( @"ICRAnnouncement" )
                        deleteLocal:bDeleteLocal
                         handleData:dataHandle
                           complete:complete
                               fail:fail];
        }
        else {
            if (fail) {
                fail( nil );
            }
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_BoardQuery] stringByAppendingFormat:@"/%@?start_date=%@&page_number=%@&page_size=%@",[[ICRUserUtil sharedInstance] userId],updateTime ? : [[NSDate dateWithTimeIntervalSince1970:0] httpParameterString],@( uiPosition ),@( uiSize )];
      NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
      NSLog(@"%@",encodeUrlStr);
    [self POST:encodeUrlStr
    parameters:nil
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doGetBoardWithID:(NSNumber *)boardID
                 success:(void (^)(id data))succ
                 failure:(void (^)(id data))fail
{
    if (!boardID) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntity:responseObject[ @"data" ]
                      objectClass:NSClassFromString( @"ICRAnnouncement" )
                       handleData:NULL
                         complete:complete
                             fail:fail];
            
    };
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
//    http://.../XFFruit-server/rest/affiche/download/{affiche_uuid}
//    http://218.244.151.129:8280/XFFruit-server/rest/affiche/download/5a7417014eb34067014eb4fea404003e 
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_BoardQuery] stringByAppendingFormat:@"/%@", boardID];
    NSLog(@"%@",urlStr);
    [self GET:urlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];
}

- (void)doReadBoardWithID:(NSNumber *)boardID
                  success:(void (^)(id data))succ
                  failure:(void (^)(id data))fail
{
    if (!boardID) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSDictionary *dictParametes =
    @{ @"readTime" : [[NSDate date] httpParameterString],
       };
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_ReadBoard] stringByAppendingFormat:@"/%@", boardID];
    [self POST:urlStr
    parameters:dictParametes
     needToken:YES
acceptTypeJson:YES
       success:success
       failure:failure];
}

#pragma mark - Patrol
- (void)doGetMyPatrolFromUpdateTime:(NSString *)updateTime
                           position:(NSUInteger)uiPosition
                               size:(NSUInteger)uiSize
                            success:(void (^)(id data))succ
                            failure:(void (^)(id data))fail
{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntities:responseObject[ @"data" ][ @"records" ]
                        objectClass:NSClassFromString( @"ICRPatrolPlan" )
                        deleteLocal:YES
                         handleData:NULL
                           complete:complete
                               fail:fail];
      };
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction: kICRHTTP_PatrolQuery]
        stringByAppendingFormat:@"/%@?&start_date=%@&page_number=%@&page_size=%@",[[ICRUserUtil sharedInstance] userId],updateTime ? : [[NSDate dateWithTimeIntervalSince1970:0] httpParameterString],@( uiPosition ),@( uiSize )];
    
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"%@",encodeUrlStr);
    [self POST:encodeUrlStr
    parameters:nil
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doGetStoreResultWithPlanID:(NSString *)planID
                           storeID:(NSString *)storeID
                           success:(void (^)(id data))succ
                           failure:(void (^)(id data))fail
{
    if (!planID || !storeID) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            void(^dataHandle)(id<IBTDatabaseObject>) = ^(id<IBTDatabaseObject> model) {
                ICRStoreResult *sR = model;
                sR.uuid = planID;
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntity:responseObject[ @"data" ]
                      objectClass:NSClassFromString( @"ICRStoreResult" )
                       handleData:dataHandle
                         complete:complete fail:fail];
        };

        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
//    请求URL:http://.../XFFruit-server/rest/patrol/plan/get_store_result/{plan_uuid}?store_uuid
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_AnswerStoreResult] stringByAppendingFormat:@"/%@?store_uuid=%@", planID, storeID];
    NSLog(@"%@",urlStr);
    [self GET:urlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];

}

- (void)doAnswerPatrolPlanWithID:(NSString *)planID
                        infoData:(id)data
                         success:(void (^)(id data))succ
                         failure:(void (^)(id data))fail
{
    if (!planID || !data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSDictionary *dictParametes = data;
    NSLog(@"data===>>>%@",data);
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_PatrolAnswer] stringByAppendingFormat:@"/%@", planID];
    NSLog(@"%@",urlStr);
    [self POST:urlStr
    parameters:dictParametes
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doAnswerOnePatrolResultWithID:(NSNumber *)resultID
                             infoData:(id)data
                              success:(void (^)(id data))succ
                              failure:(void (^)(id data))fail
{
    if (!resultID || !data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSDictionary *dictParametes = data;
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_PatrolOneAnswer] stringByAppendingFormat:@"/%@", resultID];
    [self POST:urlStr
    parameters:dictParametes
     needToken:YES
acceptTypeJson:YES
       success:success
       failure:failure];
}

#pragma mark - Task
- (void)doGetTaskListFromUpdateTime:(NSString *)updateTime
                           position:(NSUInteger)uiPosition
                               size:(NSUInteger)uiSize
                            success:(void (^)(id data))succ
                            failure:(void (^)(id data))fail
{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntities:responseObject[ @"data" ][ @"records" ]
                        objectClass:NSClassFromString( @"ICRTask" )
                          updateNil:NO
                        deleteLocal:YES
                         handleData:NULL
                           complete:complete
                               fail:fail];
        }
        else {
            if (fail) {
                fail( nil );
            }
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
       NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_MyTaskQuery] stringByAppendingFormat:@"?processor=%@&start_date=%@&page_number=%@&page_size=%@",[[ICRUserUtil sharedInstance] userCode],updateTime ? : [[NSDate dateWithTimeIntervalSince1970:0] httpParameterString],@( uiPosition ),@( uiSize )];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"%@",encodeUrlStr);
    [self POST:encodeUrlStr
    parameters:NULL
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doCreateNewTaskWithInfo:(id)data
                        success:(void (^)(id data))succ
                        failure:(void (^)(id data))fail
{
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSDictionary *dictParametes = data;
    NSLog(@"------%@",dictParametes);
    
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:kICRHTTP_TaskNew];
    [self POST:urlStr
    parameters:dictParametes
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doUpdateTaskResultID:(NSString *)resultID
                  resultText:(NSString *)resultStr
                 processDate:(NSTimeInterval)processDate
                     success:(void (^)(id data))succ
                     failure:(void (^)(id data))fail
{
    if (!resultStr) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSDictionary *dictParametes =
    @{ @"result" : resultStr
       };
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_TaskResult] stringByAppendingFormat:@"/%@/process", resultID];
    [self POST:urlStr
    parameters:dictParametes
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doSignupWithInfo:(id)data
                 success:(void (^)(id data))succ
                 failure:(void (^)(id data))fail
{
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSDictionary *dictParametes = data;
    NSLog(@"%@",dictParametes);
    
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:kICRHTTP_SignUp];
    NSLog(@"%@",urlStr);
    [self POST:urlStr
    parameters:dictParametes
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

#pragma mark - Attachment
- (void)doAddAttachment:(id)data
                success:(void (^)(id data))succ
                failure:(void (^)(id data))fail
{
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSDictionary *dictParametes = data;
    NSLog(@"%@",data);
    
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:kICRHTTP_AttachmentAdd];
     NSLog(@"%@",urlStr);
    [self POST:urlStr
    parameters:dictParametes
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doGetAttachmentListWithType:(ICRAttachmentType)eType
                              objID:(NSString *)objID
                            success:(void (^)(id data))succ
                            failure:(void (^)(id data))fail;
{
    if (eType >= kAttachmentTypeCount || !objID) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            void(^dataHandle)(id<IBTDatabaseObject>) = ^(id<IBTDatabaseObject> model) {
                ICRAttachment *att = model;
                att.objectId = objID;
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntities:responseObject[ @"result" ]
                        objectClass:NSClassFromString( @"ICRAttachment" )
                        deleteLocal:NO
                         handleData:dataHandle
                           complete:complete
                               fail:fail];
        }
        else {
            if (fail) {
                fail( nil );
            }
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dictParametes =
    @{ @"type" : ICRAttachmentTypeValue[ eType ],
       @"objectId" : objID
       };
    
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:kICRHTTP_AttachmentList];
    [self POST:urlStr
    parameters:dictParametes
     needToken:YES
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doDownloadAttachmentWithID:(NSNumber *)attachmentID
                           success:(void (^)(id data))succ
                           failure:(void (^)(id data))fail
{
    if (!attachmentID) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_AttachmentDownload] stringByAppendingFormat:@"/%@",attachmentID];
    [self GET:urlStr
    parameters:nil
     needToken:YES
acceptTypeJson:YES
       success:success
       failure:failure];
}

- (void)doAddDirectAttachment:(id)data
                      success:(void (^)(id))succ
                      failure:(void (^)(id))fail
{
    //TODO
}

+ (NSString *)AttachmentUrlWithID:(id)attachmentID {
    
    if (!attachmentID) {
        return nil;
    }
    
    return [[[self class] UrlForPluginHTTPAction:kICRHTTP_AttachmentDownloadDirect]stringByAppendingFormat:@"/%@",attachmentID];
}

- (void)doDownloadDirectAttachment:(NSString *)attachmentId
                           success:(void (^)(id))succ
                           failure:(void (^)(id))fail
{
    // TODO
}

#pragma mark - Version
- (void)doFetchVersionWithCurrent:(NSString *)currentVersion
                          success:(void (^)(id))succ
                          failure:(void (^)(id))fail
{
    if (!currentVersion) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:kICRHTTP_VersionFetch] stringByAppendingFormat:@"/%@",currentVersion];
    [self GET:urlStr
   parameters:nil
n22's avatar
n22 committed
1428
    needToken:NO
mei's avatar
mei committed
1429 1430 1431 1432 1433
acceptTypeJson:YES
      success:success
      failure:failure];
}

n22's avatar
n22 committed
1434 1435

//添加行情调研单
n22's avatar
n22 committed
1436 1437 1438
- (void)saveSurveyWithAuthenticode:(id)data
                           success:(void (^)(id))succ
                           failure:(void (^)(id))fail
1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459
{
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
陈俊俊's avatar
陈俊俊 committed
1460 1461
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
n22's avatar
n22 committed
1462
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_SurveySave] stringByAppendingFormat:@"?time=%@&operId=%@&operName=%@",currentTime,userUtil.userCode,userUtil.displayName];
陈俊俊's avatar
陈俊俊 committed
1463
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
n22's avatar
n22 committed
1464 1465 1466 1467 1468 1469
    [self POST:encodeUrlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
1470 1471 1472
}


n22's avatar
n22 committed
1473
//获取行情调研单列表
陈俊俊's avatar
陈俊俊 committed
1474 1475 1476 1477 1478 1479
- (void)querySurveyWithBillData:(id)data
                        success:(void (^)(id))succ
                        failure:(void (^)(id))fail{
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
陈俊俊's avatar
陈俊俊 committed
1480 1481
        if (succ) {
            succ( responseObject );
陈俊俊's avatar
陈俊俊 committed
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:XFFHttp_QuerySurvey];
    [self POST:urlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}


n22's avatar
n22 committed
1501 1502 1503 1504
//获取行情调研详情
- (void)getResultWithSurveyUuid:(NSString *)surveyUuid
                        success:(void (^)(id))succ
                        failure:(void (^)(id))fail{
陈俊俊's avatar
陈俊俊 committed
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
    if (!surveyUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };

n22's avatar
n22 committed
1525
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_GetSurvey] stringByAppendingFormat:@"/%@",surveyUuid];
陈俊俊's avatar
陈俊俊 committed
1526
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
n22's avatar
n22 committed
1527 1528 1529 1530
    
   [self GET:encodeUrlStr
  parameters:nil
   needToken:NO
n22's avatar
n22 committed
1531
acceptTypeJson:YES
n22's avatar
n22 committed
1532 1533
     success:success
     failure:failure];
n22's avatar
n22 committed
1534 1535
}

zhu's avatar
zhu committed
1536
//商品
陈俊俊's avatar
陈俊俊 committed
1537 1538
-(void)getProductWithStartDate:(NSString *)startDate
                   Page_number:(NSUInteger)page_number
n22's avatar
n22 committed
1539 1540 1541 1542 1543
                       page_size:(NSUInteger)page_size
                         success:(void (^)(id))succ
                         failure:(void (^)(id))fail{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
n22's avatar
n22 committed
1544 1545 1546 1547 1548 1549 1550 1551
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
陈俊俊's avatar
陈俊俊 committed
1552 1553 1554 1555 1556 1557 1558 1559 1560
            if (responseObject) {
                ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
                [dbCtrl storageEntities:responseObject[ @"data" ][ @"records" ]
                            objectClass:NSClassFromString( @"Product" )
                            deleteLocal:YES
                             handleData:NULL
                               complete:complete
                                   fail:fail];
            }
n22's avatar
n22 committed
1561 1562 1563 1564 1565
        }
        else {
            if (fail) {
                fail( nil );
            }
n22's avatar
n22 committed
1566 1567 1568 1569 1570 1571 1572 1573 1574
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
陈俊俊's avatar
陈俊俊 committed
1575
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_GetProduct] stringByAppendingFormat:@"?start_date=%@&page_number=%@&page_size=%@", startDate,@(page_number),@(page_size)];
n22's avatar
n22 committed
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:NULL
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}


陈俊俊's avatar
陈俊俊 committed
1586 1587
- (void)getUserWithStartDate:(NSString *)startDate
                 Page_number:(NSUInteger)page_number
n22's avatar
n22 committed
1588 1589 1590 1591 1592
                     page_size:(NSUInteger)page_size
                       success:(void (^)(id))succ
                       failure:(void (^)(id))fail{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
n22's avatar
n22 committed
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntities:responseObject[ @"data" ][ @"records" ]
                        objectClass:NSClassFromString( @"User" )
                        deleteLocal:YES
                         handleData:NULL
                           complete:complete
                               fail:fail];
        }
        else {
            if (fail) {
                fail( nil );
            }
n22's avatar
n22 committed
1614 1615 1616 1617 1618 1619 1620 1621
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
陈俊俊's avatar
陈俊俊 committed
1622
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_GetUser] stringByAppendingFormat:@"?start_date=%@&page_number=%@&page_size=%@", startDate,@(page_number),@(page_size)];
n22's avatar
n22 committed
1623 1624 1625 1626 1627 1628 1629 1630
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:NULL
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];

陈俊俊's avatar
陈俊俊 committed
1631
}
陈俊俊's avatar
陈俊俊 committed
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668
- (void)resultChartWithResultUuid:(NSString *)uuid
                            width:(NSNumber *)width
                           height:(NSNumber *)height
                          success:(void (^)(id))succ
                          failure:(void (^)(id))fail{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (IsDictObject(responseObject)) {
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
        }
        else {
            if (fail) {
                fail( nil );
            }
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_ResultChart] stringByAppendingFormat:@"/%@?width=%@&height=%@",uuid,width,height];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self GET:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];
}

陈俊俊's avatar
陈俊俊 committed
1669
#pragma mark - 结束行情反馈(写)
陈俊俊's avatar
陈俊俊 committed
1670
- (void)surveyFinishWithUuid:(NSString *)uuid
n22's avatar
n22 committed
1671
                     version:(NSNumber *)version
陈俊俊's avatar
陈俊俊 committed
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695
                     success:(void (^)(id))succ
                     failure:(void (^)(id))fail{
    
    if (!uuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
n22's avatar
n22 committed
1696
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_SurveyFinish] stringByAppendingFormat:@"/%@?version=%@&time=%@&operId=%@&operName=%@",uuid,version,currentTime,userUtil.userCode,userUtil.displayName];
陈俊俊's avatar
陈俊俊 committed
1697
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
n22's avatar
n22 committed
1698
    [self POST:encodeUrlStr
陈俊俊's avatar
陈俊俊 committed
1699 1700 1701 1702 1703 1704 1705
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];

}
陈俊俊's avatar
陈俊俊 committed
1706
#pragma mark - 获取行情调研单反馈列表
陈俊俊's avatar
陈俊俊 committed
1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728
- (void)getResultsWithUuid:(NSString *)uuid
                   success:(void (^)(id))succ
                   failure:(void (^)(id))fail{
    if (!uuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
陈俊俊's avatar
陈俊俊 committed
1729
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_GetResults] stringByAppendingFormat:@"/%@",uuid];
陈俊俊's avatar
陈俊俊 committed
1730
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
n22's avatar
n22 committed
1731
    [self GET:encodeUrlStr
陈俊俊's avatar
陈俊俊 committed
1732 1733 1734 1735 1736 1737 1738
    parameters:nil
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];

}
陈俊俊's avatar
陈俊俊 committed
1739
#pragma mark - 附件下载
陈俊俊's avatar
陈俊俊 committed
1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772
- (void)downLoadAttachmentWithUuid:(NSString *)uuid
                   success:(void (^)(id))succ
                   failure:(void (^)(id))fail{
    if (!uuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_Attachment] stringByAppendingFormat:@"/%@",uuid];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];
    
}

陈俊俊's avatar
陈俊俊 committed
1773
#pragma mark - 供应商
陈俊俊's avatar
陈俊俊 committed
1774 1775
-(void)getVendorWithStartDate:(NSString *)stateDate
                  Page_number:(NSUInteger)page_number
陈俊俊's avatar
陈俊俊 committed
1776 1777 1778
                       page_size:(NSUInteger)page_size
                         success:(void (^)(id))succ
                         failure:(void (^)(id))fail{
1779

陈俊俊's avatar
陈俊俊 committed
1780
 [self p_downloadWithStartDate:stateDate ICRHTTPAction:XFFHttp_GetVendor ClassName:@"Vendor" Page_number:page_number page_size:page_size success:succ failure:fail];
n22's avatar
n22 committed
1781
}
陈俊俊's avatar
陈俊俊 committed
1782
#pragma mark - 仓库
陈俊俊's avatar
陈俊俊 committed
1783 1784
-(void)getWarehouseWithStartDate:(NSString *)stateDate
                     Page_number:(NSUInteger)page_number
n22's avatar
n22 committed
1785 1786 1787
                      page_size:(NSUInteger)page_size
                        success:(void (^)(id))succ
                        failure:(void (^)(id))fail{
freecui's avatar
freecui committed
1788
    
陈俊俊's avatar
陈俊俊 committed
1789
    [self p_downloadWithStartDate:stateDate ICRHTTPAction:XFFHttp_GetWarehouse ClassName:@"Warehouse" Page_number:page_number page_size:page_size success:succ failure:fail];
freecui's avatar
freecui committed
1790
}
1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801
//用户仓库表
- (void)downloadUserWarehouseWithStartDate:(NSString *)stateDate
                               Page_number:(NSUInteger)page_number
                                 page_size:(NSUInteger)page_size
                                   success:(void (^)(id))succ
                                   failure:(void (^)(id))fail{
    [self p_downloadWithStartDate:stateDate ICRHTTPAction:XFFHttp_downloadUserWarehouse ClassName:@"UserWarehouse" Page_number:page_number page_size:page_size success:succ failure:fail];
}



陈俊俊's avatar
陈俊俊 committed
1802
#pragma mark - 科目
陈俊俊's avatar
陈俊俊 committed
1803 1804
- (void)getAccounttitleWithStartDate:(NSString *)startDate
                         Page_number:(NSUInteger)page_number
陈俊俊's avatar
陈俊俊 committed
1805 1806 1807
                             page_size:(NSUInteger)page_size
                               success:(void (^)(id))succ
                               failure:(void (^)(id))fail{
陈俊俊's avatar
陈俊俊 committed
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857
    [self p_downloadWithStartDate:startDate ICRHTTPAction:XFFHttp_GetAccounttitle ClassName:GXF_BASECLASS_ACCOUNTTITLE Page_number:page_number page_size:page_size success:succ failure:fail];
}

- (void)p_downloadWithStartDate:(NSString *)startDate
               ICRHTTPAction: (NSUInteger)urlAction
                   ClassName: (NSString *)class_Name
                 Page_number:(NSUInteger)page_number
                   page_size:(NSUInteger)page_size
                     success:(void (^)(id))succ
                     failure:(void (^)(id))fail {
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntities:responseObject[ @"data" ][ @"records" ]
                        objectClass:NSClassFromString( class_Name ) ///
                        deleteLocal:YES
                         handleData:NULL
                           complete:complete
                               fail:fail];
        }
        else {
            if (fail) {
                fail( nil );
            }
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:urlAction] stringByAppendingFormat:@"?startDate=%@&pageNumber=%@&pageSize=%@", startDate,@(page_number),@(page_size)];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [self GET:encodeUrlStr
       parameters:NULL
        needToken:NO
   acceptTypeJson:YES
          success:success
          failure:failure];
    
陈俊俊's avatar
陈俊俊 committed
1858 1859
}

陈俊俊's avatar
陈俊俊 committed
1860 1861 1862



freecui's avatar
freecui committed
1863 1864 1865 1866 1867 1868 1869 1870
- (void)getProductunitWithPage_number:(NSUInteger)page_number
                            page_size:(NSUInteger)page_size
                              success:(void (^)(id))succ
                              failure:(void (^)(id))fail {
    [self p_postDownloadWithICRHTTPAction:XFFHttp_GetProductunit ClassName:@"GXFProductUnit" Page_number:page_number page_size:page_size success:succ failure:fail];
    
}
//私有方法
freecui's avatar
freecui committed
1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895
- (void)p_getDownloadWithICRHTTPAction: (NSUInteger)urlAction
                              ClassName: (NSString *)class_Name
                            Page_number:(NSUInteger)page_number
                              page_size:(NSUInteger)page_size
                                success:(void (^)(id))succ
                                failure:(void (^)(id))fail {
    
    [self p_downloadWithIsPost:NO ICRHTTPAction:urlAction ClassName:class_Name Page_number:page_number page_size:page_size success:succ failure:fail];
}
- (void)p_postDownloadWithICRHTTPAction: (NSUInteger)urlAction
                   ClassName: (NSString *)class_Name
                 Page_number:(NSUInteger)page_number
                   page_size:(NSUInteger)page_size
                     success:(void (^)(id))succ
                                failure:(void (^)(id))fail {
    
    [self p_downloadWithIsPost:YES ICRHTTPAction:urlAction ClassName:class_Name Page_number:page_number page_size:page_size success:succ failure:fail];
}
- (void)p_downloadWithIsPost: (BOOL)isPost
               ICRHTTPAction: (NSUInteger)urlAction
                   ClassName: (NSString *)class_Name
                 Page_number:(NSUInteger)page_number
                   page_size:(NSUInteger)page_size
                     success:(void (^)(id))succ
                     failure:(void (^)(id))fail {
n22's avatar
n22 committed
1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntities:responseObject[ @"data" ][ @"records" ]
freecui's avatar
freecui committed
1909
                        objectClass:NSClassFromString( class_Name ) ///
n22's avatar
n22 committed
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926
                        deleteLocal:YES
                         handleData:NULL
                           complete:complete
                               fail:fail];
        }
        else {
            if (fail) {
                fail( nil );
            }
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
freecui's avatar
freecui committed
1927

1928
    
freecui's avatar
freecui committed
1929
#pragma 请求参数的下载时间应该有要求????     加工工厂,用[NSDate date]可以获取到数据,但是供应商获取不到 ??
freecui's avatar
freecui committed
1930

1931
    NSString *dateStr = @"2015-05-04";//[[NSDate date] httpParameterString];//urlAction
freecui's avatar
freecui committed
1932
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:urlAction] stringByAppendingFormat:@"?startDate=%@&pageNumber=%@&pageSize=%@", dateStr,@(page_number),@(page_size)];
陈俊俊's avatar
陈俊俊 committed
1933
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
freecui's avatar
freecui committed
1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951
    
    if (isPost) {
        [self POST:encodeUrlStr
        parameters:NULL
         needToken:NO
    acceptTypeJson:YES
           success:success
           failure:failure];
    } else {
        [self GET:encodeUrlStr
       parameters:NULL
        needToken:NO
   acceptTypeJson:YES
          success:success
          failure:failure];
    }
    
    
freecui's avatar
freecui committed
1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
}
//	新增行情反馈(写)
- (void)surveySaveResultWithDict: (NSDictionary *)dict surveyUuid:(NSString *)surveyUuid success:(void (^)(id))succ failure:(void (^)(id))fail {
    
    if (!dict || !surveyUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_SurveyFinish] stringByAppendingFormat:@"/?survey_uuid=%@&time=%@&operId=%@&operName=%@",surveyUuid,currentTime,userUtil.userId,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
    
陈俊俊's avatar
陈俊俊 committed
1986
}
freecui's avatar
freecui committed
1987

freecui's avatar
freecui committed
1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025

//加工单
- (void)p_postFunctionWithAction: (NSUInteger)http_action
                authenticode: (id)data
                     success: (void(^)(id))succ
                     failure: (void(^)(id))fail {
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:http_action] stringByAppendingFormat:@"?time=%@&operId=%@&operName=%@",currentTime,userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];

}
freecui's avatar
freecui committed
2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050
//7.1	保存加工单(写)
- (void)saveProcessWithAuthenticode:(id)data success:(void (^)(id))succ failure:(void (^)(id))fail
{
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
freecui's avatar
freecui committed
2051
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_SaveProcess] stringByAppendingFormat:@"?time=%@&operId=%@&operName=%@",currentTime,userUtil.userCode,userUtil.displayName];
freecui's avatar
freecui committed
2052 2053 2054 2055 2056 2057 2058 2059 2060
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}

陈俊俊's avatar
陈俊俊 committed
2061
#pragma mark - 7.2	获取加工单列表(读)
freecui's avatar
freecui committed
2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079
- (void)processQueryWithBillData:(id)data
                         success:(void (^)(id))succ
                         failure:(void (^)(id))fail {

    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:XFFHttp_QueryProcess ];
freecui's avatar
freecui committed
2080
   [self POST:urlStr parameters:dict needToken:NO acceptTypeJson:YES success:success failure:failure];
freecui's avatar
freecui committed
2081

freecui's avatar
freecui committed
2082
}
freecui's avatar
freecui committed
2083
//7.3	加工单明细(读)
freecui's avatar
freecui committed
2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121
- (void)getResultWithProcessUuid:(NSString *)processUuid
                         success:(void (^)(id))succ
                         failure:(void (^)(id))fail {
    
    if (!processUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_GetProcess] stringByAppendingFormat:@"/%@",processUuid];
    //CFURLCreateStringByAddingPercentEscapes  stringByAddingPercentEscapesUsingEncoding 对url的编码问题
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self GET:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];


}

freecui's avatar
freecui committed
2122 2123 2124 2125 2126 2127 2128 2129 2130 2131
//7.4	7.4	结束加工单(写)
- (void)finishProcessWithAuthenticode:(id)data
                              success:(void (^)(id))succ
                              failure:(void (^)(id))fail {
    [self p_postFunctionWithAction:XFFHttp_FinishProcess authenticode:data success:succ failure:fail];
}
//7.5		作废加工单
- (void)abortProcessWithAuthenticode:(id)data
                             success:(void (^)(id))succ
                             failure:(void (^)(id))fail {
freecui's avatar
freecui committed
2132

freecui's avatar
freecui committed
2133
}
n22's avatar
n22 committed
2134

陈俊俊's avatar
陈俊俊 committed
2135
#pragma mark - 添加采购单
n22's avatar
n22 committed
2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161
- (void)savePurchaseWithData:(id)data
                     success:(void (^)(id))succ
                     failure:(void (^)(id))fail
{
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
陈俊俊's avatar
陈俊俊 committed
2162
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_PurchaseSave] stringByAppendingFormat:@"?time=%@&operId=%@&operName=%@",currentTime,userUtil.userCode,userUtil.displayName];
n22's avatar
n22 committed
2163 2164 2165 2166 2167 2168 2169 2170
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}
陈俊俊's avatar
陈俊俊 committed
2171
#pragma mark - 获取采购单列表
陈俊俊's avatar
陈俊俊 committed
2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196
- (void)queryPurchaseWithData:(id)data
                        success:(void (^)(id))succ
                        failure:(void (^)(id))fail{
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:XFFHttp_QueryPurchase];
    [self POST:urlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}
陈俊俊's avatar
陈俊俊 committed
2197
#pragma mark - 获取采购单详情
陈俊俊's avatar
陈俊俊 committed
2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230
- (void)getPurchaseResultWithPurchaseUuid:(NSString *)purchaseUuid
                                  success:(void (^)(id))succ
                                  failure:(void (^)(id))fail{
    if (!purchaseUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_GetPurchaseDetail] stringByAppendingFormat:@"/%@",purchaseUuid];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self GET:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];
}
陈俊俊's avatar
陈俊俊 committed
2231
#pragma mark - 采购单处理
陈俊俊's avatar
陈俊俊 committed
2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257
- (void)dealByActionWithPurchaseUuid:(NSString *)purchaseUuid
                              action:(NSString *)action
                              remark:(NSString *)remark
                             version:(NSNumber *)version
                             success:(void (^)(id))succ
                             failure:(void (^)(id))fail{
    if (!purchaseUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
陈俊俊's avatar
陈俊俊 committed
2258
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_DealByActionPurchase] stringByAppendingFormat:@"/%@?action=%@&remark=%@&version=%@&time=%@&operId=%@&operName=%@",purchaseUuid,action,remark,version,[[NSDate date] httpParameterString],userUtil.userCode,userUtil.displayName];
陈俊俊's avatar
陈俊俊 committed
2259 2260
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
陈俊俊's avatar
陈俊俊 committed
2261 2262 2263 2264 2265 2266 2267 2268 2269
    [self POST:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];

}

陈俊俊's avatar
陈俊俊 committed
2270
#pragma mark - 添加发运单
陈俊俊's avatar
陈俊俊 committed
2271 2272 2273 2274
- (void)saveTransportWithData:(id)data
                     success:(void (^)(id))succ
                     failure:(void (^)(id))fail
{
陈俊俊's avatar
陈俊俊 committed
2275 2276 2277 2278 2279
    [self privateSaveAndSubmitWithUrl:XFFHttp_TransportSave
                                 data:data
                              success:succ
                              failure:fail];
}
陈俊俊's avatar
陈俊俊 committed
2280
#pragma mark - 保存并提交
陈俊俊's avatar
陈俊俊 committed
2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292
- (void)saveAndSubmitTransportWithData:(id)data
                               success:(void (^)(id))succ
                               failure:(void (^)(id))fail{
    [self privateSaveAndSubmitWithUrl:XFFHttp_TransportSaveAndSubmit
                                 data:data
                              success:succ
                              failure:fail];
}
- (void)privateSaveAndSubmitWithUrl:(ICRHTTPAction)url
                               data:(id)data
                            success:(void (^)(id))succ
                            failure:(void (^)(id))fail{
陈俊俊's avatar
陈俊俊 committed
2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
陈俊俊's avatar
陈俊俊 committed
2315
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:url] stringByAppendingFormat:@"?time=%@&operId=%@&operName=%@",currentTime,userUtil.userCode,userUtil.displayName];
陈俊俊's avatar
陈俊俊 committed
2316 2317 2318 2319 2320 2321 2322 2323 2324 2325
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}


陈俊俊's avatar
陈俊俊 committed
2326
#pragma mark - 获取发运单列表
陈俊俊's avatar
陈俊俊 committed
2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351
- (void)queryTransPortWithData:(id)data
                      success:(void (^)(id))succ
                      failure:(void (^)(id))fail{
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:XFFHttp_QueryTransport];
    [self POST:urlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}
陈俊俊's avatar
陈俊俊 committed
2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379

////选择发运单列表
//- (void)chooseTransPortWithData:(id)data
//                       success:(void (^)(id))succ
//                       failure:(void (^)(id))fail{
//    
//    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
//        CLog(@"%@", responseObject);
//        if (succ) {
//            succ( responseObject );
//        }
//    };
//    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
//        CLog(@"%@", error);
//        if (fail) {
//            fail( error );
//        }
//    };
//    NSDictionary *dict = data;
//    NSString *urlStr = [[self class] UrlForPluginHTTPAction:XFFHttp_QueryTransport];
//    [self POST:urlStr
//    parameters:dict
//     needToken:NO
//acceptTypeJson:YES
//       success:success
//       failure:failure];
//}

陈俊俊's avatar
陈俊俊 committed
2380
#pragma mark - 获取发运单详情
陈俊俊's avatar
陈俊俊 committed
2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405
- (void)getTransportResultWithTransportUuid:(NSString *)transportUuid
                                    success:(void (^)(id))succ
                                    failure:(void (^)(id))fail{
    if (!transportUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_GetTransportDetail] stringByAppendingFormat:@"/%@",transportUuid];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
陈俊俊's avatar
陈俊俊 committed
2406 2407 2408 2409 2410 2411
    [self GET:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];
陈俊俊's avatar
陈俊俊 committed
2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447
}


- (void)endTransportWithTransportUuid:(NSString *)transportUuid
                              version:(NSNumber *)version
                              success:(void (^)(id))succ
                              failure:(void (^)(id))fail{
    if (!transportUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_EndTransport] stringByAppendingFormat:@"/%@?version=%@&time=%@&operId=%@&operName=%@",transportUuid,version,[[NSDate date] httpParameterString],userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self POST:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];
n22's avatar
n22 committed
2448

zhu's avatar
zhu committed
2449
}
陈俊俊's avatar
陈俊俊 committed
2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487
- (void)abortTransportWithTransportUuid:(NSString *)transportUuid
                              version:(NSNumber *)version
                              success:(void (^)(id))succ
                              failure:(void (^)(id))fail{
    if (!transportUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_AbortTransport] stringByAppendingFormat:@"/%@?version=%@&time=%@&operId=%@&operName=%@",transportUuid,version,[[NSDate date] httpParameterString],userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self POST:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];
    
}



陈俊俊's avatar
陈俊俊 committed
2488
#pragma mark - 1·保存采购通知单
zhu's avatar
zhu committed
2489 2490 2491 2492
- (void)savePurchaseNoticeWithData:(id)data
                           success:(void (^)(id))succ
                           failure:(void (^)(id))fail
{
zhu's avatar
zhu committed
2493 2494 2495 2496 2497 2498
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
zhu's avatar
zhu committed
2499
    
zhu's avatar
zhu committed
2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_savePurchaseNotice] stringByAppendingFormat:@"?time=%@&operId=%@&operName=%@",currentTime,userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];

zhu's avatar
zhu committed
2524
}
陈俊俊's avatar
陈俊俊 committed
2525
#pragma mark - 2·获取采购通知单列表
zhu's avatar
zhu committed
2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551
- (void)getPurchaseNoticeListWithData:(id)data
                              success:(void (^)(id))succ
                              failure:(void (^)(id))fail
{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:XFFHttp_getPurchaseNoticeList];
    [self POST:urlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
 
}
陈俊俊's avatar
陈俊俊 committed
2552
#pragma mark - 3·采购通知单明细(读)
陈俊俊's avatar
陈俊俊 committed
2553 2554 2555
- (void)getPurchaseNoticeDetailedWithPurchaseUuid:(NSString *)purchaseUuid
                                          success:(void (^)(id))succ
                                          failure:(void (^)(id))fail
zhu's avatar
zhu committed
2556 2557
{
    
陈俊俊's avatar
陈俊俊 committed
2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588
    if (!purchaseUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_getPurchaseNoticeDetailed] stringByAppendingFormat:@"/%@",purchaseUuid];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self GET:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];
    
    
zhu's avatar
zhu committed
2589
}
陈俊俊's avatar
陈俊俊 committed
2590
#pragma mark - 4·保存并提交采购通知单
zhu's avatar
zhu committed
2591 2592 2593 2594 2595 2596
- (void)saveAndSubmitPurchaseNoticeWithData:(id)data
                                    success:(void (^)(id))succ
                                    failure:(void (^)(id))fail
{
    
}
陈俊俊's avatar
陈俊俊 committed
2597
#pragma mark - 5·提交采购通知单
zhu's avatar
zhu committed
2598 2599 2600 2601 2602 2603
- (void)ComitPurchaseNoticeWithData:(id)data
                            success:(void (^)(id))succ
                            failure:(void (^)(id))fail
{
    
}
陈俊俊's avatar
陈俊俊 committed
2604
#pragma mark - 6·接受采购通知单
陈俊俊's avatar
陈俊俊 committed
2605 2606
- (void)acceptPurchaseNoticeWithUuid:(NSString *)purchaseNoticeuuid
                             version:(NSNumber *)version
zhu's avatar
zhu committed
2607 2608 2609
                             success:(void (^)(id))succ
                             failure:(void (^)(id))fail
{
陈俊俊's avatar
陈俊俊 committed
2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631
    if (!purchaseNoticeuuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_acceptPurchaseNotice] stringByAppendingFormat:@"/%@?version=%@&time=%@&operId=%@&operName=%@",purchaseNoticeuuid,version,[[NSDate date] httpParameterString],userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
zhu's avatar
zhu committed
2632
    
陈俊俊's avatar
陈俊俊 committed
2633 2634 2635 2636 2637 2638
    [self POST:encodeUrlStr
    parameters:nil
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
zhu's avatar
zhu committed
2639
}
陈俊俊's avatar
陈俊俊 committed
2640
#pragma mark - 7·结束采购通知单
陈俊俊's avatar
陈俊俊 committed
2641 2642
- (void)finishPurchaseNoticeWithUuid:(NSString *)purchaseNoticeuuid
                             version:(NSNumber *)version
zhu's avatar
zhu committed
2643 2644 2645
                             success:(void (^)(id))succ
                             failure:(void (^)(id))fail
{
陈俊俊's avatar
陈俊俊 committed
2646 2647 2648 2649 2650 2651
    if (!purchaseNoticeuuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
zhu's avatar
zhu committed
2652
    
陈俊俊's avatar
陈俊俊 committed
2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_finishPurchaseNotice] stringByAppendingFormat:@"/%@?version=%@&time=%@&operId=%@&operName=%@",purchaseNoticeuuid,version,[[NSDate date] httpParameterString],userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self POST:encodeUrlStr
    parameters:nil
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];

zhu's avatar
zhu committed
2676
}
陈俊俊's avatar
陈俊俊 committed
2677
#pragma mark - 8·获取采购通知单跟进记录
zhu's avatar
zhu committed
2678
- (void)getPurchaseNoticeRecodWithData:(NSString *)purchaseUuid
zhu's avatar
zhu committed
2679 2680 2681
                               success:(void (^)(id))succ
                               failure:(void (^)(id))fail
{
zhu's avatar
zhu committed
2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700
    if (!purchaseUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
zhu's avatar
zhu committed
2701
    
zhu's avatar
zhu committed
2702 2703 2704 2705 2706
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_getPurchaseNoticeRecod] stringByAppendingFormat:@"/%@",purchaseUuid];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    
    NSLog(@"%@",encodeUrlStr);
陈俊俊's avatar
陈俊俊 committed
2707
    [self GET:encodeUrlStr
zhu's avatar
zhu committed
2708 2709 2710 2711 2712 2713
    parameters:nil
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];

陈俊俊's avatar
陈俊俊 committed
2714
}
陈俊俊's avatar
陈俊俊 committed
2715

陈俊俊's avatar
陈俊俊 committed
2716 2717
- (void)getProductUnitWithStartDate:(NSString *)startDate
                        Page_number:(NSUInteger)page_number
陈俊俊's avatar
陈俊俊 committed
2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751
                            page_size:(NSUInteger)page_size
                              success:(void (^)(id))succ
                              failure:(void (^)(id))fail{
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (IsDictObject(responseObject)) {
            void (^complete)(void) = ^(void){
                if (succ) {
                    [IBTCommon runOnMainThreadWithoutDeadlocking:^{
                        succ( responseObject );
                    }];
                }
            };
            
            ICRDataBaseController *dbCtrl = [ICRDataBaseController sharedController];
            [dbCtrl storageEntities:responseObject[ @"data" ][ @"records" ]
                        objectClass:NSClassFromString( @"GXFProductUnit" )
                        deleteLocal:YES
                         handleData:NULL
                           complete:complete
                               fail:fail];
        }
        else {
            if (fail) {
                fail( nil );
            }
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
陈俊俊's avatar
陈俊俊 committed
2752
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_GetProductunit] stringByAppendingFormat:@"?start_date=%@&page_number=%@&page_size=%@", startDate,@(page_number),@(page_size)];
陈俊俊's avatar
陈俊俊 committed
2753 2754 2755 2756 2757 2758 2759 2760 2761 2762
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:NULL
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];

}

陈俊俊's avatar
陈俊俊 committed
2763

陈俊俊's avatar
陈俊俊 committed
2764
#pragma mark - 获取转运单列表
陈俊俊's avatar
陈俊俊 committed
2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789
- (void)queryTransferWithData:(id)data
                       success:(void (^)(id))succ
                       failure:(void (^)(id))fail{
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:XFFHttp_QueryTransfer];
    [self POST:urlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}
陈俊俊's avatar
陈俊俊 committed
2790
#pragma mark - 添加转运单
陈俊俊's avatar
陈俊俊 committed
2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827
- (void)saveTransferWithData:(id)data
                      success:(void (^)(id))succ
                      failure:(void (^)(id))fail
{
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHTTP_TransferSave] stringByAppendingFormat:@"?time=%@&operId=%@&operName=%@",currentTime,userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}


陈俊俊's avatar
陈俊俊 committed
2828
#pragma mark - 获取转运单详情
陈俊俊's avatar
陈俊俊 committed
2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930
- (void)getTransferResultWithTransferUuid:(NSString *)transferUuid
                                  success:(void (^)(id))succ
                                  failure:(void (^)(id))fail{
    if (!transferUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_GetTransferDetail] stringByAppendingFormat:@"/%@",transferUuid];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self GET:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];
}
- (void)endTransferWithTransferUuid:(NSString *)transferUuid
                            version:(NSNumber *)version
                            success:(void (^)(id))succ
                            failure:(void (^)(id))fail{
    if (!transferUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_EndTransfer] stringByAppendingFormat:@"/%@?version=%@&time=%@&operId=%@&operName=%@",transferUuid,version,[[NSDate date] httpParameterString],userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self POST:encodeUrlStr
    parameters:nil
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
    
}
- (void)abortTransferWithTransferUuid:(NSString *)transferUuid
                                version:(NSNumber *)version
                                success:(void (^)(id))succ
                                failure:(void (^)(id))fail{
    if (!transferUuid) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_AbortTransfer] stringByAppendingFormat:@"/%@?version=%@&time=%@&operId=%@&operName=%@",transferUuid,version,[[NSDate date] httpParameterString],userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self POST:encodeUrlStr
    parameters:nil
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
    
}
陈俊俊's avatar
陈俊俊 committed
2931
#pragma mark - 保存收货单
陈俊俊's avatar
陈俊俊 committed
2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965
- (void)saveReceiveWithData:(id)data
                    success:(void (^)(id))succ
                    failure:(void (^)(id))fail{
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_SaveRctinfo] stringByAppendingFormat:@"?time=%@&operId=%@&operName=%@",currentTime,userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}
陈俊俊's avatar
陈俊俊 committed
2966
#pragma mark - 保存并收货
陈俊俊's avatar
陈俊俊 committed
2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000
- (void)saveReceiptAndReceiveWithData:(id)data
                              success:(void (^)(id))succ
                              failure:(void (^)(id))fail{
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
    NSString *currentTime = [[NSDate date] httpParameterString];
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSString *urlStr = [[[self class] UrlForPluginHTTPAction:XFFHttp_SaveReceipt] stringByAppendingFormat:@"?time=%@&operId=%@&operName=%@",currentTime,userUtil.userCode,userUtil.displayName];
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self POST:encodeUrlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
}
陈俊俊's avatar
陈俊俊 committed
3001
#pragma mark - 版本更新
zhu's avatar
zhu committed
3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026
- (void)getVeisionIdWithType:(NSString *)type
                     success:(void (^)(id))succ
                     failure:(void (^)(id))fail
{
    
    if (!type) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    
陈俊俊's avatar
陈俊俊 committed
3027
    NSString *urlStr = [NSString stringWithFormat:@"%@/%@?type=%@",HTTP_REST_API_BASE_URL,ICRHTTPInterface[XFFHttp_getVersionId],type];
zhu's avatar
zhu committed
3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038
    NSString *encodeUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [self GET:encodeUrlStr
   parameters:nil
    needToken:NO
acceptTypeJson:YES
      success:success
      failure:failure];
    
    
}
陈俊俊's avatar
陈俊俊 committed
3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071
#pragma mark - 报表首页,数据罗盘
- (void)queryHomepageWith:(id)data
                  success:(void (^)(id))succ
                  failure:(void (^)(id))fail{
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
   NSString *urlStr = [[self class] UrlForPluginHTTPAction:XFFHttp_QueryHomepage];
    [self POST:urlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];

}
3072 3073 3074 3075
#pragma mark - 查询下级组织代码
- (void)queryLowerOrgsWith:(id)data
                   success:(void (^)(id))succ
                   failure:(void (^)(id))fail{
陈俊俊's avatar
陈俊俊 committed
3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095
    if (!data) {
        if (fail) {
            fail( [[self class] ErrorWithMsg:ERROR_PARAMETER code:0] );
        }
        return;
    }
    
    void (^success)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
        CLog(@"%@", responseObject);
        if (succ) {
            succ( responseObject );
        }
    };
    void (^failure)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
        CLog(@"%@", error);
        if (fail) {
            fail( error );
        }
    };
    NSDictionary *dict = data;
3096
    NSString *urlStr = [[self class] UrlForPluginHTTPAction:XFFHttp_QueryLowerOrgs];
陈俊俊's avatar
陈俊俊 committed
3097 3098 3099 3100 3101 3102
    [self POST:urlStr
    parameters:dict
     needToken:NO
acceptTypeJson:YES
       success:success
       failure:failure];
3103

陈俊俊's avatar
陈俊俊 committed
3104 3105
}

陈俊俊's avatar
陈俊俊 committed
3106

mei's avatar
mei committed
3107
@end