public with sharing class ConsumEquipmentSetShipmentController extends CreateRelationListPagingCtrlBase{
    private String cesIdsStr;
    private List<String> cesIdList;
    public String c_apply_no { get; private set; }
    public Boolean done_flg { get;  set; }
    public Boolean readOnly { get;  set; }
    private String keywdSort = null;
    public FixtureDeliverySlip__c slip { get; set; }
    public String keepWher { get; set; }
    public String keyword { get; set; }
    public String changeMessage { get; set; }
    public String keywordDate { get; set; }
    public Boolean saveBtnDisabled { get; private set; }
    private List<Consum_Apply_Equipment_Set_Detail__c> useCaesdList;
    private Boolean cancelAction;

    public ConsumEquipmentSetShipmentController() {
        cesIdsStr = ApexPages.currentPage().getParameters().get('id');
    }

    public override Integer getSearchNumMax() {
        //各ページに制御あれば、最大件数を指定する
        // searchNumMax = Integer.valueOf(Label.Product_Select_Limit);
        // searchNumMax = 20;
        pagesize = '400';
        return searchNumMax;
    }

    /* 選択されたデータ取得用Soql　Fromから*/
    public override String getSelectedDataSql() {
        // オブジェクトAPI名
        selectedDataSql = ' where Id != null ';
        selectedDataSql += '   and (';

        for (String caesStr : cesIdList) {
            selectedDataSql += ' Consum_Apply_Equipment_Set__r.Name = \'' + String.escapeSingleQuotes(caesStr) + '\' OR Consum_Apply_Equipment_Set__c = \'' + String.escapeSingleQuotes(caesStr) + '\' OR';
        }
        selectedDataSql = selectedDataSql.removeEnd('OR');
        selectedDataSql += ')';
        selectedDataSql += '   and Shipment_request_time2__c != null';
        selectedDataSql += '   and Cancel_Select__c = False';
        //selectedDataSql += ' order by Id ASC nulls last';
        keepWher = selectedDataSql;
        selectedDataSql = ' From Consum_Apply_Equipment_Set_Detail__c' + selectedDataSql + ' order by Fixture_Model_No_F__c nulls last, Consumable_Guaranteen_end_F__c nulls last,Name';
        myComponentController.columnRightRW.put('Inspection_Cnt_Jia__c', 'r');//update      wangweipeng      2022/01/12 
        //add by yc 2021-11-26 start
        //myComponentController.columnRightRW.put('EquipmentManagementCode__c', 'r');
        //myComponentController.columnRightRW.put('ManagementCode__c', 'r');
        //add by yc 2021-11-26 end
        return selectedDataSql;
    }

    // 検索元対象オブジェクトAPI名
    public override String getOriginObjName() {
        // オブジェクトAPI名
        originObjName = 'Consum_Apply_Equipment_Set_Detail__c';
        return originObjName;
    }
    public override String getOriginObjColumns() {
        // 項目セット
        originObjColumns =  'Id';
        return originObjColumns;
    }

    public override String getObjName() {
        // オブジェクトAPI名
        objName = 'Consum_Apply_Equipment_Set_Detail__c';
        return objName;
    }
    public override String getColumnLeftFieldSetName() {
        // 左の項目セット
        columnLeftFieldSetName = '';
        return columnLeftFieldSetName;
    }
    public override String getColumnRightFieldSetName() {
        // 右の項目セット
        columnRightFieldSetName = 'ConsumEquipmentSetShipment_R';
        return columnRightFieldSetName;
    }
    public override List<String> getColumnFieldList() {
        // strColumus 里加 field
        // FixtureUtil#raesdGroupBy()の項目も必要
        return new List<String>{'Id', 'Asset__c', 'DeliverySlip__c', 'Shippment_loaner_time__c', 'Consum_Apply__r.demo_purpose2__c', 'Consum_Apply__r.Shipment_requested_cnt__c', 'Shipment_Saved_Flg__c', 'Shipment_request_time2__c', 'Consum_Apply_Equipment_Set__r.Yi_Shipment_request__c','Inspection_Cnt_Jia__c','EquipmentManagementCode__c','ManagementCode__c','boxbarcodeforReceipt__c'};
    }
    //隐藏的字段只能显示，不能赋值
    public override List<String> getHiddenFieldList() {
        return new List<String>{'Product_Serial_No_F__c'};
    }
    // add by youc 2021-12-03 start 设置大码，小码
    // 画面里直接可以输入的項目 List 在字段集里也添加了  设置读写
    public override List<String> getWritableColumnFieldList() {
        return new List<String>{'EquipmentManagementCode__c','ManagementCode__c','boxbarcodeforReceipt__c'};
    }
    // getObjName 连 getOriginObjName 的 FK
    public override String getFKColumnField() {
        return null;
    }

    public override String getRecordTypeId() {
        //ページレイアウトを収得するのレコードタイプ
        recordTypeId = '';
        return recordTypeId;
    }

    // ページコントローラに検索処理は、WhereSoql作成のみ、パラメータとして、コンポーネントに渡される
    public override String getSqlWhereStr() {
        sqlWhereStr = '';

        if(getIsNeedRunSearch()){
            System.debug('getIsNeedRunSearch enter');
            sqlWhereStr = this.makeSoql();
            System.debug('sqlWhereStr is:' + sqlWhereStr);
        }

        return sqlWhereStr;

    }

    public override String getOrderbyStr() {
        return ' order by Fixture_Model_No_F__c nulls last, Consumable_Guaranteen_end_F__c nulls last,Name';
    }

    public override Boolean getIsNeedRunSearch() {

      //   if (String.isBlank(keyword)) {
            // isNeedRunSearch = false;
      //   }else{
            // isNeedRunSearch = true;
      //   }
        return true;
    }

    public void init() {

        Set<Id> rnsIdSet = new Set<Id>();
        String jsonStr;
        cancelAction = false;
        // 当前User
        String userid = Userinfo.getUserId();
        if (cesIdsStr != null) {
            cesIdList = cesIdsStr.split(',');

            User user = [select Id,Name from User where Id = :userid];
            // 借出耗材备品一览
            List<Consum_Apply_Equipment_Set__c> rnsList = [select Id, Consum_Apply__c, Consum_Apply__r.Yi_loaner_arranged__c, Consum_Apply__r.Name, Consum_Apply__r.Shipment_Slip_tmp__c
                                            from Consum_Apply_Equipment_Set__c
                                           where (Name in :cesIdList or Id in :cesIdList)
                                             ];
            readOnly = false;
            if (rnsList.size() > 0) {
                for (Consum_Apply_Equipment_Set__c rns : rnsList) {
                    rnsIdSet.add(rns.Id);
                    if (rns.Consum_Apply__r.Shipment_Slip_tmp__c != null && jsonStr == null) {
                        jsonStr = rns.Consum_Apply__r.Shipment_Slip_tmp__c;
                    }
                    c_apply_no = rns.Consum_Apply__r.Name;
                    if (rns.Consum_Apply__r.Yi_loaner_arranged__c > 0) {
                        readOnly = true;
                    }
                }
                parentId = rnsList[0].Consum_Apply__c;
            } else {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '借出耗材备品一览不存在'));
                saveBtnDisabled = true;
                return;
            }
        }
        System.debug(jsonStr);
        if (jsonStr != null) {
            try {
                slip = (FixtureDeliverySlip__c)JSON.deserialize(jsonStr, FixtureDeliverySlip__c.class);
            } catch (Exception ex) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ex.getMessage()));
                slip = new FixtureDeliverySlip__c();
            }
        } else {
            slip = new FixtureDeliverySlip__c();
        }
        if (slip.Wh_Staff__c == null) slip.Wh_Staff__c = userid;
        slip.ConsumSlip__c = true;

        searchOppSetParam();
        getSqlWhereStr();

        // return null;
    }

    private void searchOppSetParam() {
        keywdSort = keyword;
    }

    public void searchOpp() {
        searchOppSetParam();

        if (!getIsNeedRunSearch()) {
            return;
        }

        // 選択済みの製品を取得
        myComponentController.getSelectedDataInfo();
        getSqlWhereStr();
        // コンポーネントにSoqlを発行して、ページングする
        myComponentController.searchAndPaging();
    }

    public void searchSlip() {
        String qryString = 'select Id, Shippment_loaner_time__c, ConsumSlip__c, Name, DeliveryCompany__c, Wh_Staff__c, Combine_Pack__c, Distributor_method__c, DeliveryType__c, DeliveryCompany_SlipNo__c '
                + 'from FixtureDeliverySlip__c '
                + 'where Name =\''+ slip.Name +'\' and DeliveryType__c = \'发货\'';
        if (String.isNotBlank(slip.Distributor_method__c)) {
            qryString += ' and Distributor_method__c = \''+ slip.Distributor_method__c +'\'';
        }
        if (String.isNotBlank(slip.DeliveryCompany__c)) {
            qryString += ' and DeliveryCompany__c = \''+ slip.DeliveryCompany__c +'\'';
        }
        List<FixtureDeliverySlip__c> slipList = Database.query(qryString);

        if (slipList.size() > 0) {
            if (slipList.size() > 1) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '当前条件检索到复数条运输单，请追加检索条件!'));
            }
            slip = slipList[0];
            if (slip.Wh_Staff__c == null) slip.Wh_Staff__c = Userinfo.getUserId();
        }
    }

    public void save() {
        done_flg = false;
        if (readOnly) return;
        Map<String, Integer> sendAssetKey = new Map<String, Integer>();
        //add by rentx 2021-10-22 start 设置小码 设置管理编码 下面设置完之后就清空了
        Map<Id,List<String>> xiaomaMap = new Map<Id,List<String>>();
        //add by youc 2021-12-06 保存之后，再次设置小码 显示页面
        Map<Id,List<String>> xiaomaMap1 = new Map<Id,List<String>>();
        Map<Id,List<String>> bianmaMap = new Map<Id,List<String>>();//update      wangweipeng      2022/02/21           start
        Map<Id,List<String>> bianmaMap1 = new Map<Id,List<String>>();//update      wangweipeng      2022/02/21           start
        //add by rentx 2021-10-22 end 设置小码 设置管理编码

        Map<Id,List<String>> hzMap = new Map<Id,List<String>>();
        Map<Id,List<String>> hzMap1 = new Map<Id,List<String>>();

        for (WrapperInfo wi : viewList) {
            if (!wi.check) continue;
            Consum_Apply_Equipment_Set_Detail__c caesd = (Consum_Apply_Equipment_Set_Detail__c)wi.sobj;
            //update      wangweipeng      2022/01/12           start
            Integer cnt = 0;
            if(String.isNotBlank(caesd.EquipmentManagementCode__c)){
                cnt = caesd.EquipmentManagementCode__c.split(',').size();
            }
            caesd.Inspection_Cnt_Jia__c = cnt;
            //Integer cnt = caesd.Inspection_Cnt_Jia__c == null ? 0 : Integer.valueOf(caesd.Inspection_Cnt_Jia__c);
            //update      wangweipeng      2022/01/12           end
            sendAssetKey.put(caesd.Asset__c, cnt);
            //add by rentx 2021-10-22 start 设置小码
            system.debug(caesd.Inspection_Cnt_Jia__c+'==123='+ caesd.EquipmentManagementCode__c);
            if (!xiaomaMap.containsKey(caesd.Asset__c) && caesd.EquipmentManagementCode__c != null) {
                xiaomaMap.put(caesd.Asset__c, caesd.EquipmentManagementCode__c.split(','));
            }
            if (!bianmaMap.containsKey(caesd.Asset__c) && caesd.ManagementCode__c != null) {
                bianmaMap.put(caesd.Asset__c, caesd.ManagementCode__c.split(','));
            }
            if (!xiaomaMap1.containsKey(caesd.Asset__c) && caesd.EquipmentManagementCode__c != null) {
                xiaomaMap1.put(caesd.Asset__c, caesd.EquipmentManagementCode__c.split(','));
            }
            if (!bianmaMap1.containsKey(caesd.Asset__c) && caesd.ManagementCode__c != null) {
                bianmaMap1.put(caesd.Asset__c, caesd.ManagementCode__c.split(','));
            }
            system.debug('==='+ xiaomaMap+'==bianmaMap=='+bianmaMap);
            //add by rentx 2021-10-22 end 设置小码
            if (!hzMap.containsKey(caesd.Asset__c) && caesd.boxbarcodeforReceipt__c != null) {
                hzMap.put(caesd.Asset__c, caesd.boxbarcodeforReceipt__c.split(','));
            }
            if (!hzMap1.containsKey(caesd.Asset__c) && caesd.boxbarcodeforReceipt__c != null) {
                hzMap1.put(caesd.Asset__c, caesd.boxbarcodeforReceipt__c.split(','));
            }
            system.debug('=zheli3=='+ hzMap+'==hezi=='+caesd.boxbarcodeforReceipt__c);
        }
        List<Consum_Apply_Equipment_Set_Detail__c> updList = new List<Consum_Apply_Equipment_Set_Detail__c>();
       system.debug('useCaesdList=='+useCaesdList.size());
       Map<Id, List<Consum_Apply_Equipment_Set_Detail__c>> caesdMap = new Map<Id, List<Consum_Apply_Equipment_Set_Detail__c>>();
        
        for (Consum_Apply_Equipment_Set_Detail__c caesd : useCaesdList) {
            if (sendAssetKey.containsKey(caesd.Asset__c)) {
                Integer cnt = sendAssetKey.get(caesd.Asset__c);
                if (cnt > 0) {
                    caesd.Shipment_Saved_Flg__c = true;
                    cnt--;
                } else {
                    caesd.Shipment_Saved_Flg__c = false;
                }
                sendAssetKey.put(caesd.Asset__c, cnt);
                //add by youc 2021-12-06 保存之后，再次设置小码 显示页面 start
                if (caesdMap.containsKey(caesd.Asset__c) == false) {
                    caesdMap.put(caesd.Asset__c, new List<Consum_Apply_Equipment_Set_Detail__c>());
                }
                caesdMap.get(caesd.Asset__c).add(caesd);
                //add by youc 2021-12-06 保存之后，再次设置小码 显示页面 end
   
                //add by rentx 2021-10-25 start  设置小码
                //将之前的所有"备品管理码" 制为空 再赋值 将用过的元素设置为null字符串 已保证唯一性

                caesd.EquipmentManagementCode__c = '';
                caesd.ManagementCode__c = '';
                caesd.boxbarcodeforReceipt__c = '';
                if (xiaomaMap.containsKey(caesd.Asset__c)) {
                    //获取该保有设备对应的小码集合
                    List<String> tempArr = xiaomaMap.get(caesd.Asset__c);
                    List<String> heArr = bianmaMap.get(caesd.Asset__c);
                    List<String> hzArr = hzMap.get(caesd.Asset__c);
                    System.debug('-------------11111-'+heArr+'==hzArr=='+hzArr);
                    system.debug('tempArr0'+tempArr);
                    if (tempArr != null && tempArr.size() > 0) {
                        for (Integer i = 0; i < tempArr.size(); i++) {
                            if (tempArr[i] != 'null') { 
                                caesd.EquipmentManagementCode__c = tempArr[i];
                                system.debug('zheli0'+caesd.EquipmentManagementCode__c);
                                //update      wangweipeng      2022/02/21           start
                                caesd.ManagementCode__c = heArr[i];
                                caesd.boxbarcodeforReceipt__c = hzArr[i];
                                //caesd.ManagementCode__c = bianmaMap.containsKey(caesd.Asset__c) ? bianmaMap.get(caesd.Asset__c) : '';
                                //update      wangweipeng      2022/02/21           end
                                tempArr[i] = 'null';
                                heArr[i] = 'null';
                                hzArr[i] = 'null';
                                break;
                             } 
                        }  
                    }
                }

                //if(String.isNotBlank(caesd.ManagementCode__c)){
                //    caesd.boxbarcodeforReceipt__c = caesd.Barcode_F__c + '250' + caesd.ManagementCode__c;
                //}else{
                //    caesd.boxbarcodeforReceipt__c = '';
                //}
                //设置"管理编码" 
                /**
                if(!bianmaMap.containsKey(caesd.Asset__c)){
                  caesd.ManagementCode__c = bianmaMap.containsKey(caesd.Asset__c) ? bianmaMap.get(caesd.Asset__c) : '';
                  system.debug(bianmaMap+'管理编码'+caesd.ManagementCode__c+'备品管理码'+caesd.EquipmentManagementCode__c);
                }
                **/
                //add by rentx 2021-10-25 end 设置小码
                updList.add(caesd);
            }
        }
        

        Savepoint sp = Database.setSavepoint();
        try {

            String jsonstr = JSON.serialize(slip);
            Consum_Apply__c upd_ca = new Consum_Apply__c(Id=parentId, Shipment_Slip_tmp__c=jsonstr);
            update upd_ca;
            if (updList.size() > 0) {
                update updList;    
            }
            //add by youc 2021-12-06 保存之后，再次设置小码 显示页面 start
            for (Id assId : caesdMap.keySet()) {
                Consum_Apply_Equipment_Set_Detail__c wiInfo = caesdMap.get(assId)[0];
                if (xiaomaMap1.containsKey(wiInfo.Asset__c)) {
                   wiInfo.EquipmentManagementCode__c = String.join(xiaomaMap1.get(wiInfo.Asset__c), ',');
                } 
                if (bianmaMap1.containsKey(wiInfo.Asset__c)) {
                   wiInfo.ManagementCode__c = String.join(bianmaMap1.get(wiInfo.Asset__c), ',');
                } 
                if (hzMap1.containsKey(wiInfo.Asset__c)) {
                   wiInfo.boxbarcodeforReceipt__c = String.join(hzMap1.get(wiInfo.Asset__c), ',');
                } 
            }
            //add by youc 2021-12-06 保存之后，再次设置小码 显示页面 end
            done_flg = true;
            //add by youc 2021-12-06 再次调用了下初始化方法，给输入框赋值
            // myComponentController.getSelectedDataInfo();
            // getSqlWhereStr();
            // myComponentController.searchAndPaging();
            //add by youc 2021-12-06 
        } catch (Exception ex) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ex.getMessage()));
            Database.rollback(sp);
            done_flg = false;
        }
    }

    public void send() {
        done_flg = false;
        Set<String> sendAssetKey = new Set<String>();
        Set<String> sendEquipmentSet = new Set<String>();
        for (WrapperInfo wi : viewList) {
            Consum_Apply_Equipment_Set_Detail__c caesd = (Consum_Apply_Equipment_Set_Detail__c)wi.sobj;
            if (!wi.check) {
                continue;
            }
          /**  暂时不需要提示，直接发货，保存大小码
            //add       wangweipeng              2022/01/28                   start
            //判断页面是否保存
            if(useCaesdList != null && useCaesdList.size() > 0){
                for(Consum_Apply_Equipment_Set_Detail__c caesdc : useCaesdList){
                    if(caesd.Asset__c == caesdc.Asset__c){
                        if(caesdc.Shipment_Saved_Flg__c == false){
                           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请先保存数据，在进行发货'));
                            return;
                        }
                    }
                }
            }
            //add       wangweipeng              2022/01/28                   end
            **/
            String guaranteen_end = '';
            if (caesd.Consumable_Guaranteen_end_F__c != null) {
                guaranteen_end = caesd.Consumable_Guaranteen_end_F__c.format();                     
            }
            if (caesd.Consumable_Guaranteen_end_F__c != null && Date.today().daysBetween(caesd.Consumable_Guaranteen_end_F__c) <= 0 && caesd.Consum_Apply__r.demo_purpose2__c != '动物实验' && caesd.Consum_Apply__r.demo_purpose2__c != 'ET展箱'  ) { //2021-04-30 mzy  备品课题-1577
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品已过期['+caesd.Fixture_Model_No_F__c+']('+caesd.Consumable_Guaranteen_end_F__c.format()+')'));
                return;
            }
            Integer cnt = 0;
            if(String.isNotBlank(caesd.EquipmentManagementCode__c)){
                cnt = caesd.EquipmentManagementCode__c.split(',').size();
            }
            caesd.Inspection_Cnt_Jia__c = cnt;
            system.debug('发货件数==='+caesd.Inspection_Cnt_Jia__c);
            if (caesd.Inspection_Cnt_Jia__c > caesd.Yi_Chu_Ku_Zhi_Shi_Jia__c) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '发货件数大于已出库指示件数['+caesd.Fixture_Model_No_F__c+']('+guaranteen_end+')'));
                return;
            } 
            if (caesd.Inspection_Cnt_Jia__c == null || caesd.Inspection_Cnt_Jia__c < caesd.Yi_Chu_Ku_Zhi_Shi_Jia__c) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '发货件数小于已出库指示件数['+caesd.Fixture_Model_No_F__c+']('+guaranteen_end+')'));
                return;
            }
            //add by youc 2021-12-27 start 
            if (caesd.EquipmentManagementCode__c == null) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '备品管理码为空，不能发货'));
                return;
            }

            if (caesd.ManagementCode__c == null) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '管理编码为空，不能发货'));
                return;
            }

            //add by youc 2021-12-27 end 
            if (slip.Name == null || slip.DeliveryType__c == null || slip.Distributor_method__c == null || slip.DeliveryCompany__c == null || slip.Wh_Staff__c == null ) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请填写发货信息'));
                return;
            }

            sendEquipmentSet.add(caesd.Consum_Apply_Equipment_Set__c);
            sendAssetKey.add(caesd.Asset__c);
        }        

        Integer needCnt = 0;
        Integer hadCnt = 0;
        for (Consum_Apply_Equipment_Set_Detail__c caesd : (List<Consum_Apply_Equipment_Set_Detail__c>)selectedData) {
            if (caesd.Shipment_request_time2__c != null && caesd.DeliverySlip__c == null) {
                needCnt++;
            }
        }
        Set<Id> assetIdSet = new Set<Id>();
        List<Consum_Apply_Equipment_Set_Detail__c> updList = new List<Consum_Apply_Equipment_Set_Detail__c>();
        for (Consum_Apply_Equipment_Set_Detail__c caesd : useCaesdList) {
            if (sendAssetKey.contains(caesd.Asset__c)) {
                hadCnt++;
                updList.add(caesd);
                assetIdSet.add(caesd.Asset__c);
            }
        }
 
        if (viewList.size() > 0 && (sendEquipmentSet.size() != ((Consum_Apply_Equipment_Set_Detail__c)viewList[0].sobj).Consum_Apply__r.Shipment_requested_cnt__c || hadCnt != needCnt)) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '必须整单发货，部分发货请进行分单'));
            return;
        } 

        List<Consum_Apply_Equipment_Set_Detail__c> updateList = [select Id, Shipment_request_time2__c from Consum_Apply_Equipment_Set_Detail__c where Id in :updList for update];
        for (Consum_Apply_Equipment_Set_Detail__c upd : updateList) {
            if (upd.Shipment_request_time2__c == null) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '出库指示时间为空，不能发货'));
                break;
            }
        }
        if (ApexPages.hasMessages(ApexPages.severity.Error)) {
            done_flg = false;
            return;
        }

        //add       wangweipeng                  2022/02/17               start
        save();
        //add       wangweipeng                  2022/02/17               end
        

        Savepoint sp = Database.setSavepoint();
        try {
            if (updList.size() > 0) {
                List<Asset> assetList = [
                    SELECT Id
                      FROM Asset
                     WHERE Id IN:assetIdSet
                     FOR UPDATE
                ];
                slip.Shippment_loaner_time__c = Datetime.now();
                FixtureUtil.withoutUpsertObjects(new List<FixtureDeliverySlip__c>{slip});

                Datetime nowtime = Datetime.now();
                List<Consum_Apply_Equipment_Set_Detail__c> upsertList = new List<Consum_Apply_Equipment_Set_Detail__c>();
                for (Consum_Apply_Equipment_Set_Detail__c upd : updList) {
                    //upd.DeliverySlip__c = slip.Id;
                    //upd.Shippment_loaner_time__c = nowtime;
                    //upd.StockDown__c = true;
                    //upd.StockDown_time__c = nowtime;
                    upsertList.add(
                        new Consum_Apply_Equipment_Set_Detail__c(
                            id = upd.id, 
                            Inspection_Cnt_Jia__c = upd.Inspection_Cnt_Jia__c,
                            DeliverySlip__c = slip.Id,
                            Shippment_loaner_time__c = nowtime,
                            //EquipmentManagementCode__c = upd.EquipmentManagementCode__c,
                            //ManagementCode__c = upd.ManagementCode__c,
                            StockDown__c = true
                            //, StockDown_time__c = nowtime 
                            ));
                }
                FixtureUtil.withoutUpdate(upsertList);

                Consum_Apply__c upd_ca = new Consum_Apply__c(Id=parentId, DeliverySlip__c=slip.Id);
                FixtureUtil.withoutUpdate(new List<Consum_Apply__c>{upd_ca});
            }
            searchOpp();
            done_flg = true;
        } catch (Exception ex) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ex.getMessage()));
            Database.rollback(sp);
            done_flg = false;
        }
    }

    public void cancel() {
        Set<Id> clearAssetId = new Set<Id>();
        List<Consum_Apply_Equipment_Set_Detail__c> updList = new List<Consum_Apply_Equipment_Set_Detail__c>();
        for (WrapperInfo wi : viewList) {
            Consum_Apply_Equipment_Set_Detail__c caesd = (Consum_Apply_Equipment_Set_Detail__c)wi.sobj;
            if (caesd.DeliverySlip__c == null) {
                caesd.Inspection_Cnt_Jia__c = null;
                caesd.EquipmentManagementCode__c = null; //add by youc 2022-02-27  
                caesd.ManagementCode__c = null;//add by youc 2022-02-27 
                caesd.boxbarcodeforReceipt__c = null;
                clearAssetId.add(caesd.Asset__c);
            }
        }

        for (Consum_Apply_Equipment_Set_Detail__c caesd : useCaesdList) {
            if (clearAssetId.contains(caesd.Asset__c)) {
                caesd.Shipment_Saved_Flg__c = false;
                caesd.EquipmentManagementCode__c = null; //add by youc 2022-02-27  
                caesd.ManagementCode__c = null;//add by youc 2022-02-27 
                caesd.boxbarcodeforReceipt__c = null;
                updList.add(caesd);
            }
        }
        
        Savepoint sp = Database.setSavepoint();
        try {
            if (updList.size() > 0) {
                slip = new FixtureDeliverySlip__c();
                slip.Wh_Staff__c = Userinfo.getUserId();
                String jsonstr = JSON.serialize(slip);
                Consum_Apply__c upd_ca = new Consum_Apply__c(Id=parentId, Shipment_Slip_tmp__c=jsonstr);
                update upd_ca;
                update updList;    
            }
            keyword = null;
            keywordDate = null;
            cancelAction = true;
            searchOpp();
            done_flg = true;
        } catch (Exception ex) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ex.getMessage()));
            Database.rollback(sp);
            done_flg = false;
        }
    }

    private String makeSoql() {
        // 検索条件

        // from asset
        String soql = keepWher;
        if (String.isNotBlank(keywordDate)) {
            soql += ' AND Consumable_Guaranteen_end_F__c = ' + String.escapeSingleQuotes(keywordDate.replaceAll('/', '-'));
        }
        if (String.isNotBlank(keyword)) {
            soql += ' AND Fixture_Model_No__c like \'%' + String.escapeSingleQuotes(keyword) + '%\'';
        }
        return soql;
    }

    public override void setViewList(List<Sobject> queryList) {
        viewList = new List<WrapperInfo>();
        if (queryList.size() > 0) {
            List<Consum_Apply_Equipment_Set_Detail__c> tmpList = (List<Consum_Apply_Equipment_Set_Detail__c>)queryList;
            Map<Id, Consum_Apply_Equipment_Set_Detail__c> smap = new Map<Id, Consum_Apply_Equipment_Set_Detail__c>((List<Consum_Apply_Equipment_Set_Detail__c>)selectedData);
            useCaesdList = new List<Consum_Apply_Equipment_Set_Detail__c>();
            for (Consum_Apply_Equipment_Set_Detail__c caeid : tmpList) {
                useCaesdList.add(smap.get(caeid.Id));
            }
        }
        else {
            useCaesdList = (List<Consum_Apply_Equipment_Set_Detail__c>)selectedData;
        }
        Map<Id, List<Consum_Apply_Equipment_Set_Detail__c>> caesdMap = new Map<Id, List<Consum_Apply_Equipment_Set_Detail__c>>();
        //add by rentx 2021-10-22 start 添加记录(小码记录)
        Map<Id,List<String>> recordforxiaoMaMap = new Map<Id,List<String>>();
        //add by rentx 2021-10-22 end 添加记录(小码记录)
        //add by wangweipeng 2022-02-21 start 添加盒
        Map<Id,List<String>> recordforHeMap = new Map<Id,List<String>>();
        //add by wangweipeng 2022-02-21 end 添加盒

        Map<Id,List<String>> recordforBoxMap = new Map<Id,List<String>>();

        Map<Id, Integer> cntMap = new Map<Id, Integer>();
        Map<Id, Integer> cntShipmentReqMap = new Map<Id, Integer>();
        Map<Id, Boolean> hasShipment = new Map<Id, Boolean>();
        for (Consum_Apply_Equipment_Set_Detail__c caesd : useCaesdList) {
            if (caesdMap.containsKey(caesd.Asset__c) == false) {
                caesdMap.put(caesd.Asset__c, new List<Consum_Apply_Equipment_Set_Detail__c>());
            }
            caesdMap.get(caesd.Asset__c).add(caesd);

            //add by rentx 2021-10-22 start 添加记录(小码记录)
            //有小码的添加到记录里
            if (caesd.EquipmentManagementCode__c != null && caesd.EquipmentManagementCode__c != '') {
                if (recordforxiaoMaMap.containsKey(caesd.Asset__c) == false) {
                    recordforxiaoMaMap.put(caesd.Asset__c, new List<String>());
                }
                recordforxiaoMaMap.get(caesd.Asset__c).add(caesd.EquipmentManagementCode__c);
            }
            system.debug('recordforxiaoMaMap==='+recordforxiaoMaMap);
            //add by rentx 2021-10-22 end 添加记录(小码记录)
            //add by wangweipeng 2022-02-21 start 添加盒
            if (caesd.ManagementCode__c != null && caesd.ManagementCode__c != '') {
                if (recordforHeMap.containsKey(caesd.Asset__c) == false) {
                    recordforHeMap.put(caesd.Asset__c, new List<String>());
                }
                recordforHeMap.get(caesd.Asset__c).add(caesd.ManagementCode__c);
            }
            //add by wangweipeng 2022-02-21 end 添加盒


            if (caesd.boxbarcodeforReceipt__c != null && caesd.boxbarcodeforReceipt__c != '') {
                if (recordforBoxMap.containsKey(caesd.Asset__c) == false) {
                    recordforBoxMap.put(caesd.Asset__c, new List<String>());
                }
                recordforBoxMap.get(caesd.Asset__c).add(caesd.boxbarcodeforReceipt__c);
            }
            system.debug('zheli1'+caesd.boxbarcodeforReceipt__c + 'recordforBoxMap==='+recordforBoxMap);
          
            if (caesd.Shipment_Saved_Flg__c == true) {
                Integer cnt = cntMap.containsKey(caesd.Asset__c) ? (cntMap.get(caesd.Asset__c) + 1) : 1;
                cntMap.put(caesd.Asset__c, cnt);
            }
            if (caesd.Shipment_request_time2__c != null) {
                Integer cnt = cntShipmentReqMap.containsKey(caesd.Asset__c) ? (cntShipmentReqMap.get(caesd.Asset__c) + 1) : 1;
                cntShipmentReqMap.put(caesd.Asset__c, cnt);
            }
            if (caesd.DeliverySlip__c != null) {
                hasShipment.put(caesd.Asset__c, true);
            }
        }
        for (Id assId : caesdMap.keySet()) {
            Consum_Apply_Equipment_Set_Detail__c wiInfo = caesdMap.get(assId)[0];
            
            //展示的时候需要先设置发货件数为空 add by youc 2021-12-01
            if (cntMap.containsKey(wiInfo.Asset__c)) {
                wiInfo.Inspection_Cnt_Jia__c = cntMap.get(wiInfo.Asset__c);
            }
            if (cntShipmentReqMap.containsKey(wiInfo.Asset__c)) {
                wiInfo.Yi_Chu_Ku_Zhi_Shi_Jia__c = cntShipmentReqMap.get(wiInfo.Asset__c);
            }
            //add by rentx 2021-10-22 start 添加小码
            if (recordforxiaoMaMap.containsKey(wiInfo.Asset__c)) {
                //设置小码
                wiInfo.EquipmentManagementCode__c = String.join(recordforxiaoMaMap.get(wiInfo.Asset__c), ',');
            }
            //展示的时候需要先设置管理编码为空
            //wiInfo.ManagementCode__c = '';//先注释
            //add by rentx 2021-10-22 end 设置小码
            
            //add by wangweipeng 2022-02-21 start 添加盒
            if (recordforHeMap.containsKey(wiInfo.Asset__c)) {
                //设置小码
                wiInfo.ManagementCode__c = String.join(recordforHeMap.get(wiInfo.Asset__c), ',');
            }
            //add by wangweipeng 2022-02-21 end 添加盒


            if (recordforBoxMap.containsKey(wiInfo.Asset__c)) {
                //设置小码
                wiInfo.boxbarcodeforReceipt__c = String.join(recordforBoxMap.get(wiInfo.Asset__c), ',');
            }
            system.debug('zheli2'+wiInfo.boxbarcodeforReceipt__c);

            WrapperInfo wi = new WrapperInfo(wiInfo, myComponentController);
            wi.additionalInfoMap.put('Product_Serial_No_F__c', wiInfo.Product_Serial_No_F__c);
            if (hasShipment.containsKey(wiInfo.Asset__c) && hasShipment.get(wiInfo.Asset__c)) {
                wi.canEdit = false;
            }
            
            viewList.add(wi);
        }
        if (cancelAction) {
            changeMessage = '取消';
            cancelAction = false;
        } else {
            changeMessage = ''+viewList.size();
        }
        

    }

      @TestVisible private static void test() {
        if (false == Test.isRunningTest()) return;
        Integer i = 0;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
    }
}