HttpInterface.java 48.8 KB
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 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 364 365 366 367 368 369 370 371 372 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 428 429 430 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 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 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
package com.huaheng.wms.https;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.huaheng.wms.WMSApplication;
import com.huaheng.wms.WMSLog;
import com.huaheng.wms.bean.Receipt;
import com.huaheng.wms.util.ModulesBean;
import com.huaheng.wms.bean.Location;
import com.huaheng.wms.bean.InventoryDetails;
import com.huaheng.wms.util.Constant;
import com.huaheng.wms.util.WMSUtils;
import com.huaheng.wms.bean.BillsInfo;
import com.huaheng.wms.work.check.AGVInventory;
import com.huaheng.wms.work.check.CheckService;
import com.huaheng.wms.work.check.ReceiptInventory;
import com.huaheng.wms.work.collectgoods.ColletGoodService;
import com.huaheng.wms.bean.GoodsInfo;
import com.huaheng.wms.bean.MaterialInfo;
import com.huaheng.wms.bean.ReceiptBill;
import com.huaheng.wms.bean.ReceiptInfo;
import com.huaheng.wms.https.convert.ResponseConverterFactory;
import com.huaheng.wms.work.inventoryQuery.InventoryQueryService;
import com.huaheng.wms.bean.MobileInventory;
import com.huaheng.wms.bean.ShipmentDetail;
import com.huaheng.wms.bean.ApkInfo;
import com.huaheng.wms.bean.CompanyInfo;
import com.huaheng.wms.work.login.LoginService;
import com.huaheng.wms.bean.UserBean;
import com.huaheng.wms.bean.ContainerInfo;
import com.huaheng.wms.work.onshell.OnshellService;
import com.huaheng.wms.work.picking.Materialforecast;
import com.huaheng.wms.work.picking.PickingResult;
import com.huaheng.wms.work.picking.PickingService;
import com.huaheng.wms.work.picking.ShipmentBill;
import com.huaheng.wms.work.picking.ShipmentTaskModel;
import com.huaheng.wms.work.picking.TaskDetailBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.net.URLEncoder;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

public class HttpInterface {

    public final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    private static HttpInterface insstance = null;
    private Retrofit retrofit;
    private Map<String, Object> paramMap;
    private OkHttpClient.Builder clientBuilder;

    private LoginService loginService;                      //  登录
    private ColletGoodService colletGoodService;            //  收货
    private OnshellService onshellService;                  //  上架
    private PickingService pickingService;                  //  拣货
    private InventoryQueryService inventoryQueryService;    //  库存查询
    private CheckService checkService;

    public static HttpInterface getInsstance() {
        WMSLog.d("HttpInterface insstance:" + insstance);
        if (insstance == null) {
            insstance = new HttpInterface();
        }
        return insstance;
    }

    public HttpInterface() {
        WMSLog.d("HttpInterface");
        TrustManager[] trustManager = new TrustManager[]{
                new X509TrustManager() {
                    @Override
                    public void checkClientTrusted(X509Certificate[] chain, String authType) throws
                            CertificateException {
                    }

                    @Override
                    public void checkServerTrusted(X509Certificate[] chain, String authType) throws
                            CertificateException {
                    }

                    @Override
                    public X509Certificate[] getAcceptedIssuers() {
                        return null;    // 返回null
                    }
                }
        };

        clientBuilder = new OkHttpClient.Builder();
        try {
            clientBuilder
                    .connectTimeout(HttpConstant.CONNECT_TIMEOUT, TimeUnit.SECONDS)
                    .writeTimeout(HttpConstant.WRITE_TIMEOUT, TimeUnit.SECONDS)
                    .readTimeout(HttpConstant.READ_TIMEOUT, TimeUnit.SECONDS)
//                    .addInterceptor(new UserEntityInterceptor())
//                    .addInterceptor(new LoggerInterceptor("", true))
                    .sslSocketFactory(getSSLSocketFactory())
                    .hostnameVerifier(new HostnameVerifier() {
                        @Override
                        public boolean verify(String hostname, SSLSession session) {

                            return true;
                        }
                    });
            clientBuilder.interceptors().add(new Interceptor() {
                @Override
                public Response intercept(Interceptor.Chain chain) throws IOException {
                    // 获取 Cookie
                    Response resp = chain.proceed(chain.request());
                    List<String> cookies = resp.headers("Set-Cookie");
                    String cookieStr = "";
                    if (cookies != null && cookies.size() > 0) {
                        for (int i = 0; i < cookies.size(); i++) {
                            cookieStr += cookies.get(i);
                        }
                        WMSApplication.setOkhttpCookie(cookieStr);
                    }
                    return resp;
                }
            });
            clientBuilder.interceptors().add(new Interceptor() {
                @Override
                public Response intercept(Chain chain) throws IOException {
                    // 设置 Cookie
                    String cookieStr = WMSApplication.getOkhttpCookie();
                    if (!TextUtils.isEmpty(cookieStr)) {
                        return chain.proceed(chain.request().newBuilder().header("Cookie", cookieStr).build());
                    }
                    return chain.proceed(chain.request());
                }
            });
            clientBuilder.interceptors().add(new Interceptor() {
                @Override
                public Response intercept(Chain chain) throws IOException {
                    Request request = chain.request().newBuilder()
                            .addHeader("Content-Type", "application/json")
                            .addHeader("accept", "application/json").build();
                    return chain.proceed(request);
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }

        String url = WMSUtils.getData(Constant.NETWORK);
        if(url != null) {
            retrofit = new Retrofit.Builder()
                    .client(clientBuilder.build())
                    .addConverterFactory(ResponseConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .baseUrl(url)
                    .build();
        } else {
            retrofit = new Retrofit.Builder()
                    .client(clientBuilder.build())
                    .addConverterFactory(ResponseConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .baseUrl(HttpConstant.URL)
                    .build();
        }

        paramMap = new HashMap<>();
        WMSLog.d("initService");
        initService(retrofit);
    }

    public void  reset() {
        insstance = null;
    }

    private static SSLSocketFactory getSSLSocketFactory() throws Exception {
        //创建一个不验证证书链的证书信任管理器。
        final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
            @Override
            public void checkClientTrusted(
                    java.security.cert.X509Certificate[] chain,
                    String authType) throws CertificateException {
            }

            @Override
            public void checkServerTrusted(
                    java.security.cert.X509Certificate[] chain,
                    String authType) throws CertificateException {
            }

            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new java.security.cert.X509Certificate[0];
            }
        }};

        // Install the all-trusting trust manager
        final SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
        // Create an ssl socket factory with our all-trusting manager
        return sslContext.getSocketFactory();
    }

    public void setBaseUrl(String url) {
        retrofit = new Retrofit.Builder()
                .client(clientBuilder.build())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(url)
                .build();
        initService(retrofit);
    }

    private void initService(Retrofit retrofit) {
        loginService = retrofit.create(LoginService.class);
        colletGoodService = retrofit.create(ColletGoodService.class);
        onshellService = retrofit.create(OnshellService.class);
        pickingService = retrofit.create(PickingService.class);
        inventoryQueryService = retrofit.create(InventoryQueryService.class);
        checkService = retrofit.create(CheckService.class);
    }

    public String getBaseUrl() {
        return retrofit.baseUrl().toString();
    }

    public void login(Subscriber<ArrayList<UserBean>> subscriber, String userName, String password) {
        JSONObject json = new JSONObject();
        try {
            json.put("code", userName);
            json.put("password", password);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        WMSApplication.setOkhttpCookie(null);
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = loginService.login(formBody)
                .map(new ApiResponseFunc<ArrayList<UserBean>>());

        toSubscribe(observable, subscriber);
    }

    public void getModules(Subscriber<ArrayList<ModulesBean>> subscriber, String warehouseCode, int warehouseId) {
        JSONObject json = new JSONObject();
        try {
            json.put("warehouseId", warehouseId);
            json.put("warehouseCode", warehouseCode);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = loginService.getModules(formBody)
                .map(new ApiResponseFunc<ArrayList<ModulesBean>>());

        toSubscribe(observable, subscriber);
    }


    public void heartBeat(Subscriber<String> subscriber) {
        JSONObject json = new JSONObject();
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = loginService.heartBeat(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void scanBill(Subscriber<ArrayList<ReceiptInfo>> subscriber, String code) {
        JSONObject json = new JSONObject();
        try {
            json.put("code", code);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = colletGoodService.scanBill(formBody)
                .map(new ApiResponseFunc<ArrayList<ReceiptInfo>>());

        toSubscribe(observable, subscriber);
    }

    public void sanContainer(Subscriber<String> subscriber, String code) {
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        JSONObject json = new JSONObject();
        try {
            json.put("code", code);
            json.put("companyCode", companyCode);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        WMSLog.d("scanContainer :" + json.toString());
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = colletGoodService.scanContainer(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void saveBillByPiece(Subscriber<GoodsInfo> subscriber, String receiptContainerCode, String receiptDetailId) {
        JSONObject json = new JSONObject();
        try {
            json.put("receiptContainerCode", receiptContainerCode);
            json.put("receiptDetailId", receiptDetailId);
            json.put("taskType", (short) 100);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = colletGoodService.saveBillByPiece(formBody)
                .map(new ApiResponseFunc<GoodsInfo>());

        toSubscribe(observable, subscriber);
    }

    public void saveBillByBulk(Subscriber<List<GoodsInfo>> subscriber, List<BillsInfo> billsInfos) {
        JSONArray array = new JSONArray();
        try {
            for (int i = 0; i < billsInfos.size(); i++) {
                JSONObject object = new JSONObject();
                object.put("receiptContainerCode", billsInfos.get(i).getReceiptContainerCode());
                object.put("locationCode", billsInfos.get(i).getLoation());
                object.put("receiptDetailId", billsInfos.get(i).getReceiptDetailId());
                object.put("qty", billsInfos.get(i).getQty());
                object.put("taskType", (short) 100);
                array.put(object);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("saveBillByBulk  array:" + array.toString());
        RequestBody formBody = RequestBody.create(JSON, array.toString());
        Observable observable = colletGoodService.saveBillByBulk(formBody)
                .map(new ApiResponseFunc<List<GoodsInfo>>());

        toSubscribe(observable, subscriber);
    }

    public void collectByForm(Subscriber<List<GoodsInfo>> subscriber, List<ReceiptBill> receiptBills, String location, String containerCode, int taskType) {
        JSONArray array = new JSONArray();
        try {
            for (int i = 0; i < receiptBills.size(); i++) {
                JSONObject object = new JSONObject();
                object.put("receiptContainerCode", containerCode);
                object.put("locationCode", location);
                object.put("receiptDetailId", receiptBills.get(i).getReceiptDetailId());
                object.put("qty", receiptBills.get(i).getQty());
                object.put("taskType", taskType);
                object.put("zoneCode", "LK");
                array.put(object);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("collectByForm  array:" + array.toString());
        RequestBody formBody = RequestBody.create(JSON, array.toString());
        Observable observable = colletGoodService.saveBillByBulk(formBody)
                .map(new ApiResponseFunc<List<GoodsInfo>>());

        toSubscribe(observable, subscriber);
    }

    public void getMaterial(Subscriber<MaterialInfo> subscriber, String code) {
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        JSONObject json = new JSONObject();
        try {
            json.put("code", code);
            json.put("companyCode", companyCode);
            json.put("companyId", companyId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = colletGoodService.getMaterial(formBody)
                .map(new ApiResponseFunc<MaterialInfo>());

        toSubscribe(observable, subscriber);
    }

    public void checkLocation(Subscriber<String> subscriber, String code) {
        JSONObject json = new JSONObject();
        try {
            json.put("code", code);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = colletGoodService.checkLocation(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void quickSaveGoods(Subscriber<String> subscriber, ArrayList<ReceiptBill> receiptBills) {
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        JSONArray array = new JSONArray();
        for(ReceiptBill receiptBill : receiptBills) {
            JSONObject object = new JSONObject();
            try {
                object.put("receiptContainerCode", receiptBill.getReceiptContainerCode());
                object.put("materialCode", receiptBill.getMaterialCode());
                object.put("qty", receiptBill.getQty());
                object.put("moCode", receiptBill.getMoCode());
                object.put("locationCode", receiptBill.getLocationCode());
                object.put("batch", receiptBill.getBatch());
                object.put("project", receiptBill.getProject());
                object.put("companyCode", companyCode);
                object.put("companyId", companyId);
                array.put(object);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        WMSLog.d("quickSaveGoods  array:" + array.toString());
        RequestBody formBody = RequestBody.create(JSON, array.toString());
        Observable observable = colletGoodService.quickSaveGoods(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void createReceiptTask(Subscriber<String> subscriber, String containerCode) {
        JSONObject object = new JSONObject();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        try {
            object.put("containerCode", containerCode);
            object.put("zoneCode", "LK");
            object.put("companyCode", companyCode);
            object.put("companyId", companyId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("createReceiptTask  object:" + object.toString());
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = onshellService.createReceiptTask(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void createQuickTask(Subscriber<Integer> subscriber, String containerCode) {
        JSONObject object = new JSONObject();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        try {
            object.put("containerCode", containerCode);
            object.put("companyCode", companyCode);
            object.put("companyId", companyId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("scanContainer  object:" + object.toString());
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = onshellService.createQuickTask(formBody)
                .map(new ApiResponseFunc<Integer>());

        toSubscribe(observable, subscriber);
    }

    public void scanLocationCode(Subscriber<String> subscriber, String locationCode) {
        JSONObject object = new JSONObject();
        try {
            object.put("locationCode", locationCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("scanLocationCode  locationCode:" + locationCode);
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = onshellService.scanLocationCode(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void getTaskDetails(Subscriber<TaskDetailBean> subscriber, String code) {
        JSONObject object = new JSONObject();
        try {
            object.put("code", code);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = pickingService.getTaskDetails(code)
                .map(new ApiResponseFunc<TaskDetailBean>());

        toSubscribe(observable, subscriber);
    }

    public void completeTaskDetails(Subscriber<List<PickingResult>> subscriber, List<Integer> list) {
        JSONArray array = new JSONArray();
        for(int i=0; i < list.size(); i++) {
            try {
                array.put(list.get(i));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        WMSLog.d("completeTaskDetails :" + array.toString());
        RequestBody formBody = RequestBody.create(JSON, array.toString());
        Observable observable = pickingService.completeTaskDetails(formBody)
                .map(new ApiResponseFunc<List<PickingResult>>());

        toSubscribe(observable, subscriber);
    }

    public void getInventoryForecast(Subscriber<ArrayList<String>> subscriber, String code, String companyCode, String companyId) {
        JSONObject object = new JSONObject();
        try {
            object.put("code", code);
            object.put("companyCode", companyCode);
            object.put("companyId", companyId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.getInventoryForecast(formBody)
                .map(new ApiResponseFunc<ArrayList<String>>());

        toSubscribe(observable, subscriber);
    }

    public void getInventoryInfo(Subscriber<ArrayList<MobileInventory>> subscriber, String code, String companyCode, String companyId) {
        JSONObject object = new JSONObject();
        try {
            object.put("code", code);
            object.put("companyCode", companyCode);
            object.put("companyId", companyId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("getInventoryInfo :" + object.toString());
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.getInventoryInfo(formBody)
                .map(new ApiResponseFunc<ArrayList<MobileInventory>>());

        toSubscribe(observable, subscriber);
    }

    public void createCheckOutTask(Subscriber<List<Integer>> subscriber, String ids) {
        JSONObject object = new JSONObject();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        String station = WMSUtils.getData(Constant.CURREN_STATION_ID, Constant.DEFAULT_STATION_ID);
        try {
            object.put("ids", ids);
            object.put("companyCode", companyCode);
            object.put("companyId", companyId);
            object.put("station", station);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("createCheckOutTask :" + object.toString());
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.createCheckOutTask(formBody)
                .map(new ApiResponseFunc<List<Integer>>());

        toSubscribe(observable, subscriber);
    }

    public void pickLocation(Subscriber<List<Location>> subscriber) {
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        JSONObject object = new JSONObject();
        try {
            object.put("companyCode", companyCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.pickLocation(formBody)
                .map(new ApiResponseFunc<List<Location>>());

        toSubscribe(observable, subscriber);
    }

    public void getEmptyContainerInLocation(Subscriber<List<Location>> subscriber) {
        JSONObject object = new JSONObject();
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.getEmptyContainerInLocation(formBody)
                .map(new ApiResponseFunc<List<Location>>());

        toSubscribe(observable, subscriber);
    }

    public void execute(Subscriber<String> subscriber, String taskId) {
        JSONObject object = new JSONObject();
        try {
            object.put("taskId", taskId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.execute(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void executeList(Subscriber<String> subscriber, List<Integer> taskIdList) {
        JSONArray jsonArray = new JSONArray();
        for(Integer taskId : taskIdList) {
            JSONObject object = new JSONObject();
            try {
                object.put("taskId", taskId);
                jsonArray.put(object);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        WMSLog.d("executeList  :" + jsonArray.toString());
        RequestBody formBody = RequestBody.create(JSON, jsonArray.toString());
        Observable observable = inventoryQueryService.executeList(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void transfer(Subscriber<Integer> subscriber, String sourceLocation, String destinationLocation) {
        JSONObject object = new JSONObject();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        try {
            object.put("sourceLocation", sourceLocation);
            object.put("destinationLocation", destinationLocation);
            object.put("companyCode", companyCode);
            object.put("companyId", companyId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.transfer(formBody)
                .map(new ApiResponseFunc<Integer>());

        toSubscribe(observable, subscriber);
    }

    public void isLocation(Subscriber<String> subscriber, String code) {
        JSONObject json = new JSONObject();
        try {
            json.put("code", code);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = inventoryQueryService.isLocation(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void getLocationForecast(Subscriber<ArrayList<String>> subscriber, String code, String type) {
        JSONObject json = new JSONObject();
        try {
            json.put("code", code);
            json.put("type", type);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = inventoryQueryService.getLocation(formBody)
                .map(new ApiResponseFunc<ArrayList<String>>());

        toSubscribe(observable, subscriber);
    }

    public void replenishWarehouse(Subscriber<List<GoodsInfo>> subscriber, ArrayList<ReceiptBill> receiptBills) {
        JSONArray array = new JSONArray();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        for(ReceiptBill receiptBill : receiptBills) {
            JSONObject object = new JSONObject();
            try {
                object.put("materialCode", receiptBill.getMaterialCode());
                object.put("qty", receiptBill.getQty());
                object.put("locationCode", receiptBill.getLocationCode());
                object.put("moCode", receiptBill.getMoCode());
                object.put("batch", receiptBill.getBatch());
                object.put("project", receiptBill.getProject());
                object.put("companyCode", companyCode);
                object.put("companyId",companyId);
                array.put(object);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        WMSLog.d("replenishWarehouse  array:" + array.toString());
        RequestBody formBody = RequestBody.create(JSON, array.toString());
        Observable observable = colletGoodService.replenishWarehouse(formBody)
                .map(new ApiResponseFunc<List<GoodsInfo>>());

        toSubscribe(observable, subscriber);
    }

    public void getMaterialForecast(Subscriber<List<Materialforecast>> subscriber, String code) {
        JSONObject json = new JSONObject();
        try {
            json.put("code", code);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = pickingService.getMaterialForecast(formBody)
                .map(new ApiResponseFunc<List<Materialforecast>>());

        toSubscribe(observable, subscriber);
    }

    public void autoShipment(Subscriber<List<Integer>> subscriber,  List<ShipmentBill> shipmentBills) {
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        JSONArray array = new JSONArray();
        for(ShipmentBill shipmentBill : shipmentBills) {
            JSONObject object = new JSONObject();
            try {
                object.put("materialCode", shipmentBill.getMaterialCode());
                object.put("qty", shipmentBill.getQty());
                if(shipmentBill.getLocation() != null && shipmentBill.getLocation().contains("DM")) {
                    object.put("taskType", 300);
                } else {
                    object.put("taskType", 400);
                }
                object.put("location", shipmentBill.getLocation());
                object.put("companyCode", companyCode);
                object.put("companyId", companyId);
                array.put(object);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        WMSLog.d("autoShipment :" + array.toString());
        RequestBody formBody = RequestBody.create(JSON, array.toString());
        Observable observable = pickingService.autoShipment(formBody)
                .map(new ApiResponseFunc<List<Integer>>());

        toSubscribe(observable, subscriber);
    }

    public void getContainerCode(Subscriber<String> subscriber, String code) {
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        JSONObject json = new JSONObject();
        try {
            json.put("code", code);
            json.put("companyCode", companyCode);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        WMSLog.d("getContainerCode:" + json.toString());
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = colletGoodService.getContainerCode(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void createShipTask(Subscriber<List<Integer>> subscriber, ShipmentTaskModel shipmentTaskCreateModel) {
        JSONObject json = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        for(int i = 0 ; i < shipmentTaskCreateModel.getShipmentContainerHeaderIds().length ;i++) {  //依次将数组元素添加进JSONArray对象中
            jsonArray.put(shipmentTaskCreateModel.getShipmentContainerHeaderIds()[i]);
        }
        try {
            json.put("shipmentContainerHeaderIds", jsonArray);
            json.put("taskType", shipmentTaskCreateModel.getTaskType());
            json.put("priority", shipmentTaskCreateModel.getPriority());
            json.put("companyCode", companyCode);
            json.put("companyId", companyId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = pickingService.createShipTask(formBody)
                .map(new ApiResponseFunc<List<Integer>>());

        toSubscribe(observable, subscriber);
    }

    public void createSortShipTask(Subscriber<List<Integer>> subscriber, ShipmentTaskModel shipmentTaskCreateModel) {
        JSONObject json = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        for(int i = 0 ; i < shipmentTaskCreateModel.getShipmentContainerHeaderIds().length ;i++) {  //依次将数组元素添加进JSONArray对象中
            jsonArray.put(shipmentTaskCreateModel.getShipmentContainerHeaderIds()[i]);
        }
        try {
            json.put("shipmentContainerHeaderIds", jsonArray);
            json.put("taskType", shipmentTaskCreateModel.getTaskType());
            json.put("priority", shipmentTaskCreateModel.getPriority());
            json.put("companyCode", companyCode);
            json.put("companyId", companyId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, json.toString());
        Observable observable = pickingService.createSortShipTask(formBody)
                .map(new ApiResponseFunc<List<Integer>>());

        toSubscribe(observable, subscriber);
    }

    public void completeTaskByWMS(Subscriber<String> subscriber, String taskId) {
        JSONObject object = new JSONObject();
        try {
            object.put("taskId", taskId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.completeTaskByWMS(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void completeTaskListByWMS(Subscriber<String> subscriber, List<Integer> taskIdList) {
        JSONArray jsonArray = new JSONArray();
        for(Integer taskId : taskIdList) {
            JSONObject object = new JSONObject();
            try {
                object.put("taskId", taskId);
                jsonArray.put(object);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        RequestBody formBody = RequestBody.create(JSON, jsonArray.toString());
        Observable observable = inventoryQueryService.completeTaskListByWMS(formBody)
                .map(new ApiResponseFunc<String>());
        toSubscribe(observable, subscriber);
    }

    public void createReplenishTask(Subscriber<Integer> subscriber, String containerCode, String station) {
        JSONObject object = new JSONObject();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        try {
            object.put("containerCode", containerCode);
            object.put("companyCode", companyCode);
            object.put("companyId", companyId);
            object.put("station", station);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = onshellService.createReplenishTask(formBody)
                .map(new ApiResponseFunc<Integer>());

        toSubscribe(observable, subscriber);
    }

    public void createEmptyIn(Subscriber<Integer> subscriber, String containerCode, String destinationLocation) {
        JSONObject object = new JSONObject();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        try {
            object.put("containerCode", containerCode);
            object.put("destinationLocation", destinationLocation);
            object.put("companyCode", companyCode);
            object.put("companyId", companyId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("createEmptyIn :" + object.toString());
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.createEmptyIn(formBody)
                .map(new ApiResponseFunc<Integer>());

        toSubscribe(observable, subscriber);
    }

    public void createEmptyOut(Subscriber<Integer> subscriber, String containerCode, String sourceLocation) {
        JSONObject object = new JSONObject();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        String companyId = WMSUtils.getData(Constant.CURREN_COMPANY_ID, Constant.DEFAULT_COMPANY_ID);
        String station = WMSUtils.getData(Constant.CURREN_STATION_ID, Constant.DEFAULT_STATION_ID);
        try {
            object.put("containerCode", containerCode);
            object.put("sourceLocation", sourceLocation);
            object.put("companyCode", companyCode);
            object.put("companyId", companyId);
            object.put("station", station);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("createEmptyOut :" + object.toString());
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.createEmptyOut(formBody)
                .map(new ApiResponseFunc<Integer>());

        toSubscribe(observable, subscriber);
    }

    public void getLocationFromContainer(Subscriber<String> subscriber, String containerCode) {
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        JSONObject object = new JSONObject();
        try {
            object.put("containerCode", containerCode);
            object.put("companyCode", companyCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("getLocationFromContainer :" + containerCode);
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = onshellService.getLocationFromContainer(formBody)
                .map(new ApiResponseFunc<String>());
        toSubscribe(observable, subscriber);
    }

    public void pickingReturn(Subscriber<String> subscriber) {
        JSONObject object = new JSONObject();
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.pickingReturn(formBody)
                .map(new ApiResponseFunc<String>());
        toSubscribe(observable, subscriber);
    }

    public void get7daysShipment(Subscriber<List<InventoryDetails>> subscriber) {
        JSONObject object = new JSONObject();
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.get7daysShipment(formBody)
                .map(new ApiResponseFunc<List<InventoryDetails>>());
        toSubscribe(observable, subscriber);
    }

    public void getTodayShipmentDetail(Subscriber<List<ShipmentDetail>> subscriber) {
        JSONObject object = new JSONObject();
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = inventoryQueryService.getTodayShipmentDetail(formBody)
                .map(new ApiResponseFunc<List<ShipmentDetail>>());
        toSubscribe(observable, subscriber);
    }

    public void getCompanyInfo(Subscriber<List<CompanyInfo>> subscriber) {
        JSONObject object = new JSONObject();
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = loginService.getCompanyInfo(formBody)
                .map(new ApiResponseFunc<List<CompanyInfo>>());
        toSubscribe(observable, subscriber);
    }

    public void getUpdateApkInfo(Subscriber<ApkInfo> subscriber, String pkgName, String versionCode) {
        JSONObject object = new JSONObject();
        try {
            object.put("pkgName", pkgName);
            object.put("versionCode", versionCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = loginService.getUpdateApkInfo(formBody)
                .map(new ApiResponseFunc<ApkInfo>());

        toSubscribe(observable, subscriber);
    }

    public void scanBarcodeAdd(Subscriber<String> subscriber, int area, int flag, String barcode) {
        String loginName = WMSUtils.getData(Constant.LOGIN_NAME);
        JSONObject object = new JSONObject();
        try {
            object.put("area", area);
            object.put("barcode", barcode);
            object.put("flag", flag);
            object.put("createdBy", loginName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = colletGoodService.scanBarcodeAdd(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void getShelfInventory(Subscriber<ArrayList<AGVInventory>> subscriber, String goodsShlfNo, String side) {
        JSONObject object = new JSONObject();
        try {
            object.put("goodsShlfNo", goodsShlfNo);
            object.put("side", side);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("getShelfInventory:" + object.toString());
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = checkService.getShelfInventory(formBody)
                .map(new ApiResponseFunc<ArrayList<AGVInventory>>());

        toSubscribe(observable, subscriber);
    }

    public void scanContainerFromGoodsShelfNo(Subscriber<String> subscriber, String code, String goodsShlfNo, String side) {
        JSONObject object = new JSONObject();
        try {
            object.put("code", code);
            object.put("goodsShlfNo", goodsShlfNo);
            object.put("side", side);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("scanContainerFromGoodsShelfNo:" + object.toString());
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = checkService.scanContainerFromGoodsShelfNo(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void quickCheck(Subscriber<String> subscriber, List<ReceiptInventory> receiptInventorys) {
        JSONArray array = new JSONArray();
        JSONObject object;
        for(ReceiptInventory receiptInventory : receiptInventorys) {
            try {
                String inventory = new Gson().toJson(receiptInventory);
                object = new JSONObject(inventory);
                array.put(object);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        WMSLog.d("quickCheck:" + array.toString());
        RequestBody formBody = RequestBody.create(JSON, array.toString());
        Observable observable = checkService.quickCheck(formBody)
                .map(new ApiResponseFunc<String>());
        toSubscribe(observable, subscriber);
    }

    public void callBox(Subscriber<String> subscriber, String containerCode, String destinationLocation, int type) {
        JSONObject object = new JSONObject();
        String companyCode = WMSUtils.getData(Constant.CURREN_COMPANY_CODE, Constant.DEFAULT_COMPANY_CODE);
        try {
            object.put("containerCode", containerCode);
            object.put("destinationLocation", destinationLocation);
            object.put("type", type);
            object.put("companyCode", companyCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("callBox :" + object.toString());
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = colletGoodService.callBox(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void findReceipt(Subscriber<Receipt> subscriber, String receiptCode, String companyCode) {
        JSONObject object = new JSONObject();
        try {
            object.put("receiptCode", receiptCode);
            object.put("companyCode", companyCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        WMSLog.d("findReceipt :" + object.toString());
        RequestBody formBody = RequestBody.create(JSON, object.toString());
        Observable observable = colletGoodService.findReceipt(formBody)
                .map(new ApiResponseFunc<Receipt>());

        toSubscribe(observable, subscriber);
    }

    public void quickReceipt(Subscriber<String> subscriber, List<ReceiptBill> receiptBills) {
        JSONObject json = new JSONObject();
        String post = new Gson().toJson(receiptBills);
        post = post.replace("\\", "");
        post = post.replace("}\"}", "}}");
        post = post.replace("\"{", "{");
        post = post.replace("\"}\"", "\"}");
        WMSLog.d("quickReceipt :" + post);
        RequestBody formBody = RequestBody.create(JSON, post);
        Observable observable = colletGoodService.quickReceipt(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    public void quickNoListReceipt(Subscriber<String> subscriber, List<ReceiptBill> receiptBills) {
        JSONObject json = new JSONObject();
        String post = new Gson().toJson(receiptBills);
        post = post.replace("\\", "");
        post = post.replace("}\"}", "}}");
        post = post.replace("\"{", "{");
        post = post.replace("\"}\"", "\"}");
        WMSLog.d("quickNoListReceipt :" + post);
        RequestBody formBody = RequestBody.create(JSON, post);
        Observable observable = colletGoodService.quickNoListReceipt(formBody)
                .map(new ApiResponseFunc<String>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 用来统一处理Http的resultCode,并将HttpResult的Data部分剥离出来返回给subscriber
     *
     * @param <T> Subscriber真正需要的数据类型,也就是Data部分的数据类型
     */
    private class ApiResponseFunc<T> implements Func1<ApiResponse<T>, T> {

        @Override
        public T call(ApiResponse<T> apiResponse) {
            if (!apiResponse.getCode().equals("200")) {
                throw new ApiException(apiResponse.getMsg());
            }

            if (apiResponse.getData() != null) {
                return apiResponse.getData();
            } else if (apiResponse.getSession() != null) {
                return apiResponse.getSession();
            }

            return null;
        }
    }

    private void toSubscribe(Observable observable, Subscriber subscriber) {
        observable
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


}