/**
     * @Author    lijinhuan
*/
@isTest
private class FrameNumUploadControllerTest {
    static testMethod void testMethod1() {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeOppandStaTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass(ContactTriggerHandler.class.getName());
        Oly_TriggerHandler.bypass(AgencyHospitalHandler.class.getName());

        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 = 'N2656630';
        prd.ProductCode = 'N2656630';
        prd.Name = 'N2656630';
        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 = '22K';
        assnew.Name = 'NA-201SX-4021:一次性使用吸引活检针';
        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 = 'N2656630:22K(KVWMX)';
        assnew.TracingCode__c = 'KVWMX'; // ※
        assnew.Posting_Date__c = Date.valueOf('2021-08-20');
        
        upsert assnew;
        //发货DN
        Statu_Achievements_DN__c statuAchievementsDN = new Statu_Achievements_DN__c();
        statuAchievementsDN.Statu_Achievements__c = Sac.Id;
        statuAchievementsDN.DeliveryDate__c = Date.valueOf('2021-08-20');
        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;
        statuAchievementsDNDetails.SerialNoorLotNo_Raw__c = '22K'; // ※
        statuAchievementsDNDetails.TracingCode_Raw__c = 'KVWMX'; // ※
        upsert statuAchievementsDNDetails;
        // Olympus日历
        OlympusCalendar__c OlympusCalendar = new OlympusCalendar__c();
        OlympusCalendar.Date__c = Date.valueOf('2021-08-20');
        upsert OlympusCalendar;
        OlympusCalendar__c OlympusCalendar2 = new OlympusCalendar__c();
        OlympusCalendar2.Date__c = Date.valueOf('2022-05-10');
        upsert OlympusCalendar2;
        // 
        FileAddress__c file = new FileAddress__c();

        file.DownloadLink__c ='url123&fileName=Contact';
        file.FileName__c ='FY2305-ET01-3.pdf';//※
        file.ViewLink__c ='url123';
        file.ParentRecordId__c ='FrameNumManage'; // ※
        file.AWS_File_Key__c = '123';
        insert file;

        PageReference ref =  new PageReference('/apex/FrameNumUpload');
        String csvStr = '出库单号,物料,物料描述,机身号/批次号,数量,扫描日期,管理编号,报关品名,分类,出证,报关单,商检证,起始日,结束日';
        csvStr += '\r\n';
        String csvStrOk = csvStr+ '65289024,N2656630,NA-201SX-4021:一次性使用吸引活检针,22K,1,2022/05/10,KVWMX,一次性使用吸引活检针,ET,是,FY2305-ET01-3,FY2305-ET01-3,2022/05/10,2022/05/14';
        String csvStrErr = csvStr+ '65289024,N2656630,NA-201SX-4021:一次性使用吸引活检针,22K,1,2022/05/10,KVWMX,一次性使用吸引活检针,ET1111,是不是,FY2305-ET01-3,FY2305-ET01-3,2022/05/10,2022/05/14';
        
        FrameNumUploadController Controller = new FrameNumUploadController();
        ref.getParameters().put('csvData', csvStrErr);
        Test.setCurrentPage(ref);
        Controller.importCSVFile();

        ref.getParameters().put('csvData', csvStrOk);
        Test.setCurrentPage(ref);
        Controller.importCSVFile();

        List<FrameNumManage__c> FrameNumManageList = [select Id,InspectionCard__c from FrameNumManage__c];
        System.assertEquals(1, FrameNumManageList.size());
        FrameNumManageList[0].InspectionCard__c = '不要';
        update FrameNumManageList;
        SetFrameNumManageWebService.updateFrameNumManag(FrameNumManageList[0].Id);// 关联数据 按钮      
    }

    // 为了 SetFrameNumManageWebService 批量删除按钮
    static testMethod void testMethod2() {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeOppandStaTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass(ContactTriggerHandler.class.getName());
        Oly_TriggerHandler.bypass(AgencyHospitalHandler.class.getName());

        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 = 'N2656630';
        prd.ProductCode = 'N2656630';
        prd.Name = 'N2656630';
        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 = '22K';
        assnew.Name = 'NA-201SX-4021:一次性使用吸引活检针';
        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 = 'N2656630:22K(KVWMX)';
        
        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;
        statuAchievementsDNDetails.SerialNoorLotNo_Raw__c = '22K'; // ※
        statuAchievementsDNDetails.TracingCode_Raw__c = 'KVWMX'; // ※
        upsert statuAchievementsDNDetails;
      
        // 
        FileAddress__c file = new FileAddress__c();

        file.DownloadLink__c ='url123&fileName=Contact';
        file.FileName__c ='FY2305-ET01-3.pdf';//※
        file.ViewLink__c ='url123';
        file.ParentRecordId__c ='FrameNumManage'; // ※
        file.AWS_File_Key__c = '123';
        insert file;

        PageReference ref =  new PageReference('/apex/FrameNumUpload');
        String csvStr = '出库单号,物料,物料描述,机身号/批次号,数量,扫描日期,管理编号,报关品名,分类,出证,报关单,商检证,起始日,结束日,上传日';
        csvStr += '\r\n';
        String csvStrOk = csvStr+ '65289024,N2656630,NA-201SX-4021    : 一次性使用吸引活检针,22K,1,2022/5/10,KVWMX,一次性使用吸引活检针,ET,是,FY2305-ET01-3,FY2305-ET01-3,2022/5/10,2022/5/14,2022/6/14';
        String csvStrErr = csvStr+ '65289024,N2656630,NA-201SX-4021    : 一次性使用吸引活检针,22K,1,2022/5/10,KVWMX,一次性使用吸引活检针,ET1111,是,FY2305-ET01-3,FY2305-ET01-3,2022/5/10,2022/5/14,2022/6/14';
        
        ref.getParameters().put('csvData', csvStrErr);
        Test.setCurrentPage(ref);
        FrameNumUploadController Controller = new FrameNumUploadController();
        Controller.importCSVFile();

        ref.getParameters().put('csvData', csvStrOk);
        Test.setCurrentPage(ref);
        Controller.importCSVFile();

        List<FrameNumManage__c> FrameNumManageList = [select Id,InspectionCard__c from FrameNumManage__c];
        System.assertEquals(1, FrameNumManageList.size());
        // 正常删除
        List<String> Ids = new List<String>{FrameNumManageList[0].Id};
        SetFrameNumManageWebService.BatchDelete(Ids); // 批量删除 按钮 
        // catch 
        List<String> IdsErr = new List<String>{'aaaaaaaaaaaaa'};
        SetFrameNumManageWebService.BatchDelete(IdsErr);     
    }

    // 关联进口单证  按钮
    static testMethod void testMethod3() {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeOppandStaTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass(ContactTriggerHandler.class.getName());
        Oly_TriggerHandler.bypass(AgencyHospitalHandler.class.getName());

        Oly_TriggerHandler.bypass(ESignFormHandler.class.getName());

        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 = 'N2656630';
        prd.ProductCode = 'N2656630';
        prd.Name = 'N2656630';
        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 = '22K';
        assnew.Name = 'NA-201SX-4021:一次性使用吸引活检针';
        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 = 'N2656630:22K(KVWMX)';
        
        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;
        statuAchievementsDNDetails.SerialNoorLotNo_Raw__c = '22K'; // ※
        statuAchievementsDNDetails.TracingCode_Raw__c = 'KVWMX'; // ※
        upsert statuAchievementsDNDetails;
      
        // 签收单
        //新建电子签收单
        eSignForm__c eSignForm = new eSignForm__c();
        eSignForm.Statu_Achievements__c = Sac.Id;
        eSignForm.Statu_Achievements_DN__c = statuAchievementsDN.Id;
        eSignForm.Name = '::测试电子签收单';
        eSignForm.DNName__c = '2021082049';
        eSignForm.AccessoriesQualified__c = true;
        eSignForm.handleOpinionAgency__c = '哇哈哈哈哈哈哈哈哈';
        eSignForm.agencyScanDay__c = Date.today();
        eSignForm.agencySignUpDate__c =Date.today();
        eSignForm.agencyConfirmDate__c = Date.today();

        insert eSignForm;

        SetFrameNumManageWebService.insertFrameNumManag(statuAchievementsDN.Id,eSignForm.Id);// 插入
        SetFrameNumManageWebService.insertFrameNumManag(statuAchievementsDN.Id,eSignForm.Id);// 更新
        // 触发器 DNDetailsHandler 测试类
        update statuAchievementsDNDetails;
        // delete statuAchievementsDNDetails;
        List<Statu_Achievements_DN_details__c> temList =  [select Id from Statu_Achievements_DN_details__c where id = :statuAchievementsDNDetails.Id];
        System.assertEquals(1, temList.size());
        delete temList;
        List<Statu_Achievements_DN_details__c> temList1 =  [select Id from Statu_Achievements_DN_details__c where id = :statuAchievementsDNDetails.Id];
        System.assertEquals(0, temList1.size());

    }
    // 触发器 DNDetailsHandler 测试类
    static testMethod void testMethod4() {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeOppandStaTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass(ContactTriggerHandler.class.getName());
        Oly_TriggerHandler.bypass(AgencyHospitalHandler.class.getName());

        Oly_TriggerHandler.bypass(ESignFormHandler.class.getName());

        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 = 'N2656630';
        prd.ProductCode = 'N2656630';
        prd.Name = 'N2656630';
        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 = '22K';
        assnew.Name = 'NA-201SX-4021:一次性使用吸引活检针';
        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 = 'N2656630:22K(KVWMX)';
        
        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;
        // 签收单
        //新建电子签收单
        eSignForm__c eSignForm = new eSignForm__c();
        eSignForm.Statu_Achievements__c = Sac.Id;
        eSignForm.Statu_Achievements_DN__c = statuAchievementsDN.Id;
        eSignForm.Name = '::测试电子签收单';
        eSignForm.DNName__c = '2021082049';
        eSignForm.AccessoriesQualified__c = true;
        eSignForm.handleOpinionAgency__c = '哇哈哈哈哈哈哈哈哈';
        eSignForm.agencyScanDay__c = Date.today();
        eSignForm.agencySignUpDate__c =Date.today();
        eSignForm.agencyConfirmDate__c = Date.today();

        insert eSignForm;

        
        //发货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;
        statuAchievementsDNDetails.SerialNoorLotNo_Raw__c = '22K'; // ※
        statuAchievementsDNDetails.TracingCode_Raw__c = 'KVWMX'; // ※
        upsert statuAchievementsDNDetails;
    }
        
}