@isTest
private class InstallationDateShipmentDateTest {
    static testMethod void testMethod1() {
        List < RecordType > rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '病院'
        ];
        if (rectCo.size() == 0) {
            return;
        }
        List < RecordType > rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '戦略科室分類 呼吸科'
        ];
        if (rectSct.size() == 0) {
            return;
        }
        List < RecordType > rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '診療科 消化科'
        ];
        if (rectDpt.size() == 0) {
            return;
        }
        //签收单最终用户记录类型
        List < RecordType > recordTypeList = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '戦略科室分類 呼吸科'
        ];
        if (recordTypeList.size() == 0) {
            return;
        }
        // 省
        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        upsert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        upsert al2;
        // 产品
        Product2 prd = new Product2();
        prd.ProductCode_Ext__c = 'K10035368';
        prd.ProductCode = 'K10035368';
        prd.Name = 'K10035368';
        prd.Manual_Entry__c = false;
        upsert prd;
        //客户医院
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name = 'NFM008TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name = '*';
        depart.Department_Name__c = 'NFM008TestDepart';
        depart.ParentId = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c = company.Id;
        upsert depart;
        //签收单最终用户记录类型
        Account recordType = new Account();
        recordType.RecordTypeId = recordTypeList[0].Id;
        recordType.Name = '*';
        recordType.Department_Class_Label__c = '消化科';
        recordType.ParentId = company.Id;
        recordType.Hospital_Department_Class__c = company.Id;
        upsert recordType;
        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'
            and DeveloperName = 'Opportunity'
        ];
        //询价
        Opportunity opp = new Opportunity(Name = 'testOpp1', StageName = '引合', CloseDate = Date.today(), AccountId = depart.Id, Sales_Root__c = '販売店', Competitor__c = 'A', Click_Close_Date__c = null, RecordType = rectOpp);
        upsert opp;
        //注残
        Statu_Achievements__c Sac = new Statu_Achievements__c(name = 'zhucan_one', Opportunity__c = opp.id, DeliveryDate__c = Date.today(), ContractNO__c = 'ContractNO1', ContractAmount__c = 100);
        insert Sac;
        //保有设备
        Asset assnew = new Asset(Asset_Owner__c = 'Olympus');
        assnew.Backorder__c = Sac.Id;
        // assnew.Order_number__c = Sac.Id;
        assnew.RecordTypeId = System.Label.Asset_RecordType;
        assnew.SerialNumber = '22033591';
        assnew.Name = 'assnew';
        assnew.Product2Id = prd.Id;
        assnew.Hospital__c = company.Id;
        assnew.Department_Class__c = section.Id;
        assnew.AccountId = depart.Id;
        assnew.Asset_Owner__c = '医院资产';
        assnew.Quantity = 1;
        assnew.Status = '有库存';
        assnew.Manage_type__c = '个体管理';
        assnew.Internal_asset_location__c = '北京 备品中心';
        assnew.Loaner_accsessary__c = true;
        assnew.Delete_Flag__c = false;
        assnew.Freeze_sign__c = false;
        assnew.Out_of_wh__c = 0;
        assnew.CIC_call_back_check__c = true;
        assnew.Product_Serial_No__c = 'K10035368:22033591';
        upsert assnew;
        //发货DN
        Statu_Achievements_DN__c statuAchievementsDN = new Statu_Achievements_DN__c();
        statuAchievementsDN.Statu_Achievements__c = Sac.Id;
        statuAchievementsDN.Name = '2021082049';
        statuAchievementsDN.endUser__c = recordType.Id;
        upsert statuAchievementsDN;
        //发货DN明细
        Statu_Achievements_DN_details__c statuAchievementsDNDetails = new Statu_Achievements_DN_details__c();
        statuAchievementsDNDetails.Statu_Achievements_DN__c = statuAchievementsDN.Id;
        statuAchievementsDNDetails.Name = 'z1c200000292wse';
        statuAchievementsDNDetails.asset__c = assnew.Id;
        upsert statuAchievementsDNDetails;
       
        BatchIF_Log__c batchIf = new BatchIF_Log__c(
        RowDataFlg__c = true,
        // createdDate__c = 2021-2-01,
        Type__c = 'NFM008',
        Log2__c = '',
        Log__c = '[{"InstallationInfoI":[{"SLMark":"S","SerialNo":"2163283","ReturnExchangeReplenishMark":"","Quantity":1.0,"PurposeOfAdvice":"2","ProvistonPeriod":null,"MaterialNo":"N3803830","Location":"","InstallationDateI":"20210414","GuaranteeType":"","GuaranteePeriod":"01"},{"SLMark":"S","SerialNo":"7093913","ReturnExchangeReplenishMark":"","Quantity":1.0,"PurposeOfAdvice":"2","ProvistonPeriod":null,"MaterialNo":"N5374330","Location":"","InstallationDateI":"20210414","GuaranteeType":"","GuaranteePeriod":"01"},{"SLMark":"S","SerialNo":"22033591","ReturnExchangeReplenishMark":"","Quantity":1.0,"PurposeOfAdvice":"2","ProvistonPeriod":null,"MaterialNo":"K10035368","Location":"","InstallationDateI":"20210414","GuaranteeType":"","GuaranteePeriod":"01"},{"SLMark":"S","SerialNo":"7138403","ReturnExchangeReplenishMark":"","Quantity":1.0,"PurposeOfAdvice":"2","ProvistonPeriod":null,"MaterialNo":"N3805760","Location":"","InstallationDateI":"20210414","GuaranteeType":"","GuaranteePeriod":"01"},{"SLMark":"S","SerialNo":"7142670","ReturnExchangeReplenishMark":"","Quantity":1.0,"PurposeOfAdvice":"2","ProvistonPeriod":null,"MaterialNo":"N3805860","Location":"","InstallationDateI":"20210414","GuaranteeType":"","GuaranteePeriod":"01"},{"SLMark":"S","SerialNo":"7072131","ReturnExchangeReplenishMark":"","Quantity":1.0,"PurposeOfAdvice":"2","ProvistonPeriod":null,"MaterialNo":"5685852","Location":"","InstallationDateI":"20210414","GuaranteeType":"","GuaranteePeriod":"01"},{"SLMark":"S","SerialNo":"2146922","ReturnExchangeReplenishMark":"","Quantity":1.0,"PurposeOfAdvice":"2","ProvistonPeriod":null,"MaterialNo":"N3803530","Location":"","InstallationDateI":"20210414","GuaranteeType":"","GuaranteePeriod":"01"}],"InstallationInfoH":{"PurposeOfAdvice":"2","PostingDate":"20210318","InstallationDateH":"20210414","InquiryNo":"BJHK-GI-153P078","EntryDate":"20210511","DepartmentCode":"8080790","DeliveryNote":"0065246784","CompanyCode":"0008080761"}}]');
        insert batchIf;
        List < String > strList = new List<String>();
        strList.add(batchIf.Id);
        Database.executeBatch(new InstallationDateShipmentDate(strList),1);
       
    }
    // @IsTest
    // static void Test503() {
    //     List < String > strList = new List<String>();
    //     strList.add('a001000001g3jtz');
    //     Test.StartTest();
    //     Database.executeBatch(new InstallationDateShipmentDate(strList),1);
    //     Test.stopTest();
    // }
}