@isTest
private class lexSelectAssetEstimateVMControllerTest {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    private static User staticUser;
    private static Maintenance_Contract_Estimate__c staticContactEsti;
    static Asset createAsset(String input, String accountid, String dcId, String hpId, String serialNo, String prId, String mark ) {
        Asset asset = new Asset();
        asset.Name = input;
        asset.AccountId = accountid;
        asset.Department_Class__c = dcId;
        asset.Hospital__c = hpId;
        asset.SerialNumber = serialNo;
        asset.Product2Id = prId;
        asset.InstallDate = Date.today();
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
        //在接收参数的时候新增了String类型的Mark字段,以及在调用该方法时传递了String类型的Mark字段
        asset.AssetMark__c = mark;
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---End 
        insert asset;
        return asset;
    }

    public class AssetInfo {
        public Integer lineNo {get; private set;}
        public Boolean rec_checkBox_c {get; set;}
        public Asset rec { get; set; }
        public Maintenance_Contract_Asset_Estimate__c mcae { get; set; }
        public Boolean isManual { get; set; }
        public Decimal orgPrice {get; private set;}
        public Id getRecId() {
            Id rtn = null;
            if (rec != null) {
                rtn = rec.Id;
            }
            return rtn;
        }
        public void setRecId(Id value) {
            // なにもしない
        }
        
        // Manual専用
        public AssetInfo(Integer lineNo) {
            this.lineNo = lineNo;
            this.rec = null;
            this.mcae = new Maintenance_Contract_Asset_Estimate__c(
                isNew__c = true
            );
            this.isManual = true;
            this.rec_checkBox_c = false;
            this.orgPrice = 0;
        }
    }
    //构造数据
    @TestSetup
    public static void setup(){
        ControllerUtil.EscapeNFM001Trigger = true;

        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        u3.HR_Post__c='总裁';
        insert u3;
        lexSelectAssetEstimateVMControllerTest.staticUser = u3;
        system.runAs(u3) {
            Address_Level__c address = new Address_Level__c(Level1_Code__c = 'CN-01',Name='北京市');
            insert address;
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            hospital.Is_Active__c = '有效';
            hospital.TradeComplianceStatus__c = '警示名单';
            hospital.State_Master__c = address.Id;
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            
            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;
            
            // 価格表エントリを作成する        
            PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            entry.Product2Id = productA.Id;
            insert entry;
            
            // 納入機器を作成する
            Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'耗材');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'主机');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'耗材');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'主机');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');
            
            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;

            insert contract;

            Maintenance_Contract__c contractLastyear = new Maintenance_Contract__c();
            contractLastyear.Name = 'tect contract contractLastyear';
            contractLastyear.Not_Upper_limit_reason__c = 'tect contract contractLastyear';
            contractLastyear.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contractLastyear.Hospital__c = hospital.Id;
            contractLastyear.Department_Class__c = strategicDep[0].Id;
            contractLastyear.Department__c = dep.Id;
            contractLastyear.Service_Contract_Staff__c = u3.Id;
            contractLastyear.Contract_End_Date__c = Date.newInstance(2023, 1, 1);
            contractLastyear.Last_year_service_contract__c = contract.Id;

            insert contractLastyear;
            
            // 维修合同/保有设备を作成する
            Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c();
            mca1.Asset__c = asset01.Id;
            mca1.Estimate_List_Price__c = 100;
            mca1.Maintenance_Contract__c = contract.Id;
            
            Maintenance_Contract_Asset__c mca2 = new Maintenance_Contract_Asset__c();
            mca2.Asset__c = asset01.Id;
            mca2.Estimate_List_Price__c = 100;
            mca2.Maintenance_Contract__c = contract.Id;
            
            Maintenance_Contract_Asset__c mca3 = new Maintenance_Contract_Asset__c();
            mca3.Asset__c = asset01.Id;
            mca3.Estimate_List_Price__c = 100;
            mca3.Maintenance_Contract__c = contractLastyear.Id;
            

            insert new Maintenance_Contract_Asset__c[] {mca1, mca2,mca3};

            asset01.CurrentContract_F_asset__c = mca2.id;
            update asset01;
            asset02.CurrentContract_F_asset__c = mca3.id;
            update asset02;
            Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Name = 'contract estimate 1',
                Maintenance_Contract__c = contract.Id,
                Contract_Esti_Start_Date__c = Date.today().addDays(1),
                Request_quotation_Amount__c = 1,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test'
            );
            insert contactEsti1;
            
            Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
            mcae1.Asset__c = asset01.Id;
            mcae1.Adjustment_Upper_price__c = 1;
            mcae1.Adjustment_Lower_price__c = 1;
            mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae1.Estimate_List_Price__c = 1000;
            mcae1.Check_Result__c = 'OK';

            //lwc add
            mcae1.Asset_Consumption_rate__c = 10;
            
            Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c();
            mcae2.Asset__c = asset01.Id;
            mcae2.Adjustment_Upper_price__c = 1;
            mcae2.Adjustment_Lower_price__c = 1;
            mcae2.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae2.Estimate_List_Price__c = 1000;
            mcae2.Check_Result__c = 'OK';

            Maintenance_Contract_Asset_Estimate__c mcae3 = new Maintenance_Contract_Asset_Estimate__c();
            mcae3.Asset__c = asset01.Id;
            mcae3.Adjustment_Upper_price__c = 1;
            mcae3.Adjustment_Lower_price__c = 1;
            mcae3.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae3.Estimate_List_Price__c = 1000;
            mcae3.Check_Result__c = 'OK';
            mcae3.Product_Manual__c = productA.Id;
            
            insert new Maintenance_Contract_Asset_Estimate__c[] {mcae1, mcae2,mcae3};

            Achievement_linkage__c objAchievementlinkage = new Achievement_linkage__c(Consumption_rate_Lower__c =100, Consumption_rate_Upper__c=10,
                                                PriceCount_Lower__c =100, PriceCount_Upper__c = 20,Name = 'test');
            insert objAchievementlinkage;

            
        }

    }

    static testMethod void testInitById() {
        System.Test.startTest();
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        system.runAs(u3) {

            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];

            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            
        }
        System.Test.stopTest();

    }
    static testMethod void testInitByCopyId() {
        System.Test.startTest();
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        system.runAs(u3) {

            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            Maintenance_Contract__c contract = [SELECT Id,Past_Contract_end_day__c,Estimate_Num__c FROM Maintenance_Contract__c WHERE Not_Upper_limit_reason__c = 'tect contract' LIMIT 1];

            lexSelectAssetEstimateVMControllerTest.staticContactEsti = contactEsti1;
            String initResByCopyId = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'copyid');
            System.assertEquals(true, initResByCopyId.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataByCopyId = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResByCopyId, lexSelectAssetEstimateVMController.InitData.class);
        }
        System.Test.stopTest();

    }
    static testMethod void testInitByMcid() {
        System.Test.startTest();
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        system.runAs(u3) {

            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            Maintenance_Contract__c contract = [SELECT Id,Past_Contract_end_day__c,Estimate_Num__c FROM Maintenance_Contract__c WHERE Not_Upper_limit_reason__c = 'tect contract' LIMIT 1];
            Maintenance_Contract__c contractNoEstimate = [SELECT Id,Past_Contract_end_day__c,Estimate_Num__c FROM Maintenance_Contract__c WHERE Not_Upper_limit_reason__c = 'tect contract contractLastyear' LIMIT 1];

            lexSelectAssetEstimateVMControllerTest.staticContactEsti = contactEsti1;
            String initResByMcid = lexSelectAssetEstimateVMController.init(contract.Id,'mcid');
            String initResByMcidLastYear = lexSelectAssetEstimateVMController.init(contractNoEstimate.Id,'mcid');
            System.assertEquals(true, initResByMcid.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataMcid = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResByMcid, lexSelectAssetEstimateVMController.InitData.class);

        }
        System.Test.stopTest();

    }
    static testMethod void testSave() {
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id,EndUserType__c,Request_quotation_Amount__c,mainTalksTime__c,talksStartDate__c,Improve_ConsumptionRate_Idea__c,GuidePrice_Up__c
                                                             ,Contract_Esti_Start_Date__c FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];


            lexSelectAssetEstimateVMController.InitData transInitDataById =  new lexSelectAssetEstimateVMController.InitData();
            transInitDataById.estimate = contactEsti1;
            transInitDataById.estimate.Discount_reason__c =  'test save';

            transInitDataById.estimate.Contract_Range__c = 10;

            transInitDataById.estimate.GuidePrice_Up__c = 0;

            transInitDataById.checkedAssets = new List<lexSelectAssetEstimateVMController.AssetInfo>();
            transInitDataById.currPage = 1;
            transInitDataById.selRecordOption = '20';
            transInitDataById.totalRecords = 0;
            transInitDataById.checkDealerId = '';
            //2021-11-30 fy add LJPH-C8W8FV 置顶 start
            transInitDataById.TopProductModel.add('CF-LV1I');
            transInitDataById.TopProductModel.add('CF-LV1L');
            transInitDataById.TopProductModel.add('CV-V1');
            transInitDataById.TopProductModel.add('GIF-LV1');
            transInitDataById.TopProductModel.add('OER-AW');
            transInitDataById.TopProductModel.add('OER-A');
            //2021-11-30 fy add LJPH-C8W8FV 置顶 end
            transInitDataById.typeresult = null;
            transInitDataById.changedAfterPrint = false;
            transInitDataById.changedSubmitPrice = false;
            transInitDataById.isSaveOrApproval = false;
            transInitDataById.OldContractStartDate = null;
            transInitDataById.OldMaintenancePrice = null;
            transInitDataById.inDicideFlag = false;
            transInitDataById.isSoft = false;
            transInitDataById.activeOn = true;
            
            //LJPH-BSS6E2  ---20200911 ---update by rentongxiao start
            transInitDataById.contr = '1';
            transInitDataById.val1 = '主机';
            
            String saveResById = lexSelectAssetEstimateVMController.save(JSON.serialize(transInitDataById));
            System.assertEquals(true, saveResById != null);

            transInitDataById.estimate.Contract_Esti_Start_Date__c = Date.today();
            saveResById = lexSelectAssetEstimateVMController.save(JSON.serialize(transInitDataById));
            // for exc
            saveResById = lexSelectAssetEstimateVMController.save('');
            System.Test.stopTest();

        }
    }
    
    static testMethod void testSave1() {
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id,EndUserType__c,Request_quotation_Amount__c,mainTalksTime__c,talksStartDate__c,Improve_ConsumptionRate_Idea__c,GuidePrice_Up__c
                                                             ,Contract_Esti_Start_Date__c FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];


            lexSelectAssetEstimateVMController.InitData transInitDataById =  new lexSelectAssetEstimateVMController.InitData();
            transInitDataById.estimate = contactEsti1;
            transInitDataById.estimate.Discount_reason__c =  'test save';

            transInitDataById.estimate.Contract_Range__c = 10;

            transInitDataById.estimate.GuidePrice_Up__c = 0;

            transInitDataById.checkedAssets = new List<lexSelectAssetEstimateVMController.AssetInfo>();
            transInitDataById.currPage = 1;
            transInitDataById.selRecordOption = '20';
            transInitDataById.totalRecords = 0;
            transInitDataById.checkDealerId = '';
            //2021-11-30 fy add LJPH-C8W8FV 置顶 start
            transInitDataById.TopProductModel.add('CF-LV1I');
            transInitDataById.TopProductModel.add('CF-LV1L');
            transInitDataById.TopProductModel.add('CV-V1');
            transInitDataById.TopProductModel.add('GIF-LV1');
            transInitDataById.TopProductModel.add('OER-AW');
            transInitDataById.TopProductModel.add('OER-A');
            //2021-11-30 fy add LJPH-C8W8FV 置顶 end
            transInitDataById.typeresult = null;
            transInitDataById.changedAfterPrint = false;
            transInitDataById.changedSubmitPrice = false;
            transInitDataById.isSaveOrApproval = false;
            transInitDataById.OldContractStartDate = null;
            transInitDataById.OldMaintenancePrice = null;
            transInitDataById.inDicideFlag = true;
            transInitDataById.isSoft = false;
            transInitDataById.activeOn = true;
            transInitDataById.contract= new Maintenance_Contract__c();
            transInitDataById.contract.Contract_End_Date__c = null;
            //LJPH-BSS6E2  ---20200911 ---update by rentongxiao start
            transInitDataById.contr = '1';
            transInitDataById.val1 = '主机';
            
            String saveResById = lexSelectAssetEstimateVMController.save(JSON.serialize(transInitDataById));
            System.assertEquals(true, saveResById != null);

            transInitDataById.estimate.Contract_Esti_Start_Date__c = Date.today();
            saveResById = lexSelectAssetEstimateVMController.save(JSON.serialize(transInitDataById));
            System.Test.stopTest();

        }
    }

    static testMethod void testOnChDealerUpdate() {
        System.Test.startTest();
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        system.runAs(u3) {

            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];

            lexSelectAssetEstimateVMControllerTest.staticContactEsti = contactEsti1;
            Account hospital =  [SELECT Id FROM Account WHERE Is_Active__c = '有效' LIMIT 1];
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.estimate.Discount_reason__c =  'test save';
            transInitDataById.estimate.Contract_Range__c = 10;

            String onChDealerUpdateResById = lexSelectAssetEstimateVMController.onChDealerUpdate(JSON.serialize(contactEsti1),hospital.Id);
            // for exc
            onChDealerUpdateResById = lexSelectAssetEstimateVMController.onChDealerUpdate('',hospital.Id);
            String refreshProductDataResById = lexSelectAssetEstimateVMController.refreshProductData(JSON.serialize(transInitDataById.checkedAssets),JSON.serialize(transInitDataById.TopProductModel),10,10);
            transInitDataById.checkedAssets[0].mcae.Product_Manual__c = [SELECT Id,Name FROM Product2 WHERE  Name='テスト商品' LIMIT 1].Id;
            refreshProductDataResById = lexSelectAssetEstimateVMController.refreshProductData(JSON.serialize(transInitDataById.checkedAssets),JSON.serialize(transInitDataById.TopProductModel),0,10);
            Boolean getMCAEIsCreateableResById = lexSelectAssetEstimateVMController.getMCAEIsCreateable();

            List<Asset> assetList = [SELECT Id, Maintenance_Price_Month__c, Posting_Date__c, InstallDate FROM Asset WHERE Name='asset01' OR  Name='asset02' OR  Name='asset03'];

            List<Id> IdList = new List<Id>();
            String idsStr = '';
            for (Asset assetObj : assetList) {
                idsStr +='\''+ assetObj.Id+'\',';
            }
            List<Asset> saveBeforeCheckPriceChangeAssetResById = lexSelectAssetEstimateVMController.saveBeforeCheckPriceChangeAsset(idsStr.substring(0,idsStr.length()-1));
            System.assertEquals(true, saveBeforeCheckPriceChangeAssetResById != null, 'saveBeforeCheckPriceChangeAsset 异常');

            idsStr = '';
            List<Product2> product2List = [SELECT Id,Name FROM Product2 WHERE  Name='テスト商品'];
            for (Product2 product2Obj : product2List) {
                idsStr +='\''+ product2Obj.Id+'\',';
            }
            List<Product2> saveBeforeCheckPriceChangeProduct2ResById = lexSelectAssetEstimateVMController.saveBeforeCheckPriceChangeProduct2(idsStr.substring(0,idsStr.length()-1));

            System.assertEquals(true, saveBeforeCheckPriceChangeProduct2ResById != null, 'saveBeforeCheckPriceChangeProduct2 异常');
        }
        System.Test.stopTest();

    }
    static testMethod void testSearchBtnEquals() {
        System.Test.startTest();
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {

            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.estimate.Discount_reason__c =  'test save';
            transInitDataById.estimate.Contract_Range__c = 10;
           
            String saveResById = lexSelectAssetEstimateVMController.save(JSON.serialize(transInitDataById));
            String approvalProcessResById = lexSelectAssetEstimateVMController.approvalProcess(JSON.serialize(transInitDataById));
            String decideResById = lexSelectAssetEstimateVMController.decide(JSON.serialize(transInitDataById));
            String saveAndCancelResById = lexSelectAssetEstimateVMController.saveAndCancel(JSON.serialize(transInitDataById));
            Maintenance_Contract_Estimate__c contactEstiObj = [SELECT Id,Discount_reason__c FROM Maintenance_Contract_Estimate__c WHERE Name = 'contract estimate 1'];
            System.assertEquals(true,contactEstiObj.Discount_reason__c == 'test save');

            transInitDataById.text1 = 'S:AssetMark__c';
            transInitDataById.cond1 = 'equals';
            transInitDataById.val1 = '';
            String searchBtnResById = lexSelectAssetEstimateVMController.searchBtn(JSON.serialize(transInitDataById));
            System.assertEquals(true, searchBtnResById != null);
        }
        System.Test.stopTest();
    }
    static testMethod void testSearchBtnEqualsWithVal() {
        
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            String addNewRowsResById = lexSelectAssetEstimateVMController.addNewRows(JSON.serialize(transInitDataById.checkedAssets));
            // for exc
            addNewRowsResById = lexSelectAssetEstimateVMController.addNewRows('');

            transInitDataById.text1 = 'S:AssetMark__c';
            transInitDataById.cond1 = 'equals';
            
            transInitDataById.val1 = '耗材,主机';
            String searchBtnResById = lexSelectAssetEstimateVMController.searchBtn(JSON.serialize(transInitDataById));
            System.assertEquals(true, searchBtnResById != null);
            System.Test.stopTest();

        }
    }
    static testMethod void testSearchBtnNotEquals() {
        
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.estimate.Discount_reason__c =  'test save';
            transInitDataById.estimate.Contract_Range__c = 10;

            transInitDataById.text1 = 'S:AssetMark__c';
            transInitDataById.cond1 = 'notequals';
            transInitDataById.val1 = '';
            String searchBtnResById = lexSelectAssetEstimateVMController.searchBtn(JSON.serialize(transInitDataById));
            System.assertEquals(true, searchBtnResById != null);
            
            transInitDataById.val1 = '耗材,主机';
            searchBtnResById = lexSelectAssetEstimateVMController.searchBtn(JSON.serialize(transInitDataById));
            System.Test.stopTest();
        }
    }
    static testMethod void testSearchBtnContains() {
        
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.estimate.Discount_reason__c =  'test save';
            transInitDataById.estimate.Contract_Range__c = 10;

            transInitDataById.text1 = 'S:AssetMark__c';
            transInitDataById.cond1 = 'contains';
            transInitDataById.val1 = '';
            String searchBtnResById = lexSelectAssetEstimateVMController.searchBtn(JSON.serialize(transInitDataById));
            System.assertEquals(true, searchBtnResById != null);
            
            transInitDataById.val1 = '耗材,主机';
            searchBtnResById = lexSelectAssetEstimateVMController.searchBtn(JSON.serialize(transInitDataById));

            transInitDataById.val1 = '耗材 主机';
            searchBtnResById = lexSelectAssetEstimateVMController.searchBtn(JSON.serialize(transInitDataById));

            transInitDataById.cond1 = 'starts with';
            searchBtnResById = lexSelectAssetEstimateVMController.searchBtn(JSON.serialize(transInitDataById));
            System.Test.stopTest();

        }
    }
    static testMethod void testExchangeAsset(){
        
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.unCheckedAssets[0].rec_checkBox_c = true;
            //Maintenance_Contract__c 上一期维修合同 
            Maintenance_Contract__c objMaintenanceContract = [SELECT Id,Contract_Consumption_rate__c FROM Maintenance_Contract__c WHERE Not_Upper_limit_reason__c = 'tect contract' LIMIT 1];
            System.debug(LoggingLevel.INFO, '***testExchangeAsset objMaintenanceContract: ' + objMaintenanceContract);
            transInitDataById.unCheckedAssets[0].rec.CurrentContract_F__c = objMaintenanceContract.Id;
            // transInitDataById.unCheckedAssets[0].mcae.Asset_Consumption_rate__c = 100;

            transInitDataById.estimate.Discount_reason__c =  'test save';
            transInitDataById.estimate.Contract_Range__c = 10;

            transInitDataById.text1 = 'S:AssetMark__c';
            transInitDataById.cond1 = 'contains';
            transInitDataById.val1 = '';

            String exchangeAssetResById = lexSelectAssetEstimateVMController.exchangeAsset(JSON.serialize(transInitDataById));
            System.assertEquals(true, exchangeAssetResById != null);
            // for exc
            exchangeAssetResById = lexSelectAssetEstimateVMController.exchangeAsset('');

            Maintenance_Contract__c contractNoEstimate = [SELECT Id,Past_Contract_end_day__c,Estimate_Num__c FROM Maintenance_Contract__c WHERE Not_Upper_limit_reason__c = 'tect contract contractLastyear' LIMIT 1];
            // contract.Hospital_Salesdepartment__c = '6.华南';

            String initResByMcidLastYear = lexSelectAssetEstimateVMController.init(contractNoEstimate.Id,'mcid');
            exchangeAssetResById = lexSelectAssetEstimateVMController.exchangeAsset(initResByMcidLastYear);
            System.Test.stopTest();

        }
    }
    static testMethod void testApprovalProcess() {
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];

        
        system.runAs(u3) {
            
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            String approvalProcessResById = lexSelectAssetEstimateVMController.approvalProcess(JSON.serialize(transInitDataById));
            System.assertEquals(true, approvalProcessResById != null);
            System.Test.stopTest();

        }
    }
    static testMethod void testShowLTYRepair() {
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];

        
        system.runAs(u3) {
            
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.estimate.Discount_reason__c =  'test save';
            transInitDataById.estimate.Contract_Range__c = 10;

            String showLTYRepairResById = lexSelectAssetEstimateVMController.ShowLTYRepair(transInitDataById.targetEstimateId);
            //for exc
            showLTYRepairResById = lexSelectAssetEstimateVMController.ShowLTYRepair('');
            
            String toApprovalProcessResById = lexSelectAssetEstimateVMController.toApprovalProcess(JSON.serialize(transInitDataById));
            toApprovalProcessResById = lexSelectAssetEstimateVMController.toApprovalProcess('');
            String decideResById = lexSelectAssetEstimateVMController.decide(JSON.serialize(transInitDataById));
            String decideCancleResById = lexSelectAssetEstimateVMController.decideCancle(JSON.serialize(transInitDataById));
            decideCancleResById = lexSelectAssetEstimateVMController.decideCancle('');
            String undecideResById = lexSelectAssetEstimateVMController.undecide(transInitDataById.targetEstimateId,JSON.serialize(contactEsti1));
            System.assertEquals(true, undecideResById != null);
            System.Test.stopTest();

        }
    }
    static testMethod void testDecideSyncEstimateById() {
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {
            System.Test.startTest();

            //init id
            Maintenance_Contract_Estimate__c contactEsti2 = [SELECT Id,Contract_Esti_Start_Date__c,Contract_Range__c,Process_Status__c,EndUserType__c,Request_quotation_Amount__c,mainTalksTime__c,talksStartDate__c,Improve_ConsumptionRate_Idea__c,GuidePrice_Up__c
                                                             ,Contract_Start_Date__c FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            Maintenance_Contract_Asset_Estimate__c mcae = [SELECT Id,IsNew__c,Check_Object__c,Product_Manual__c,Estimate_List_Price__c,Check_Result__c,Repair_Price__c,Repair_Price_pass__c
                                                        ,Comment__c,EquipmentGuaranteeFlgTxt__c,Estimate_Cost__c,Adjustment_ratio_Upper__c,Adjustment_ratio_Lower__c,Adjustment_Upper_price__c
                                                        ,LastMContract_Price__c,Adjustment_Lower_price__c,Asset_Consumption_rate__c,Maintenance_Contract_Estimate__r.Contract_Esti_Start_Date__c
                                                        ,Estimate_List_Price_Page__c,Third_Party_Return__c,Product_Manual__r.Maintenance_Price_Month__c,Product_Manual__r.EquipmentGuaranteeFlg__c
                                                        ,Product_Manual__r.Asset_Model_No__c,Product_Manual__r.IS_StandardPricing__c,Asset__r.OwnershipMachine_No__c
                                                        ,Product_Manual__r.Category4__c 
                                                        FROM Maintenance_Contract_Asset_Estimate__c 
                                                        WHERE Maintenance_Contract_Estimate__c =:contactEsti2.Id AND Product_Manual__c != null LIMIT 1];
            // transInitDataById.checkedAssets.add(new lexSelectAssetEstimateVMController.AssetInfo(1,mcae));
            lexSelectAssetEstimateVMController.AssetInfo objAssetInfo = new lexSelectAssetEstimateVMController.AssetInfo(1,mcae);
            // contactEsti2.Process_Status__c = '批准';
            // update contactEsti2;
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti2.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.estimate.Discount_reason__c =  'test save';
            transInitDataById.estimate.Contract_Range__c = 10;

            String decideSyncEstimateResById = lexSelectAssetEstimateVMController.syncEstimate(true,true,transInitDataById);

            // transInitDataById.contract.
            transInitDataById.estimate.Process_Status__c = '批准';
            decideSyncEstimateResById = lexSelectAssetEstimateVMController.syncEstimate(false,true,transInitDataById);

            transInitDataById.changedAfterPrint = true;
            transInitDataById.estimate.Maintenance_Price__c = 0;
            decideSyncEstimateResById = lexSelectAssetEstimateVMController.syncEstimate(true,true,transInitDataById);
            System.assertEquals(true, decideSyncEstimateResById != null);
            System.Test.stopTest();
        }
    }
    static testMethod void testDecideSyncEstimateByMcid() {
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {

            System.Test.startTest();
            //mcid id
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id, Name, Maintenance_Contract__c, Estimation_Decision__c, CreatedDate, Service_Contract_Staff__c,
                                                             JingliApprovalManager__c, BuchangApprovalManager__c, ZongjianApprovalManager__c, Finally_Approved_Staff__c,
                                                             Contract_Esti_Start_Date__c, Contract_Esti_End_Date__c, Contract_Range__c, Contract_Start_Date__c, Contract_End_Date__c,
                                                             Maintenance_Contract_Status__c, Discount_reason__c, Improve_ConsumptionRate_Idea__c, Process_Status__c,
                                                             Estimate_Trial_Money__c, Maintenance_Price__c, Department__c, PrintDate__c, Quote_Date__c, Submit_quotation_day__c,
                                                             Examination_Price__c, Service_contract_target_number__c,IS_Reduced_price_approval__c,
                                                             Maintenance_Contract__r.Payment_Plan_Sum_First__c, Maintenance_Contract__r.Payment_Plan_Date_First__c,
                                                             Maintenance_Contract__r.Payment_Plan_Sum_Second__c,
                                                             Maintenance_Contract__r.Payment_Plan_Sum_Third__c,
                                                             Maintenance_Contract__r.Payment_Plan_Sum_Forth__c,
                                                             Maintenance_Contract__r.Payment_Plan_Sum_Fifth__c,
                                                             Maintenance_Contract__r.Payment_Plan_Sum_Sixth__c,
                                                             Discount_Price__c, Discount_Percentage__c, IsSyncing__c,
                                                             NotUse_Oxygenated_Water__c, Estimate_Target__c, Dealer__c,Dealer__r.FirstParagraphEnd__c,Is_RecognitionModel__c,
                                                             Append_Condition_Price__c, Asset_Sum_Price__c, Asset_Repair_Sum_Price__c,
                                                             Print_Contract__c, Print_RepairPrice__c, Print_DiscountPercentage__c, Print_Agent__c, Change_Dealer_Approval__c,
                                                             Print_DiscountPrice__c, Print_ListPrice__c, Print_MaintePrice__c, Print_SumPrice__c, Print_Tripartite__c, TKZongjianApprovalManager__c
                                                             //打印报价（简化版） 2019/12/18 start
                                                             , IS_Clone_After_Decide__c, New_contract_offer__c, NewEstimation_Amount__c, EndUserType__c, Print_Simplify__c
                                                             //打印报价（简化版） 2019/12/18 end
                                                             //最低价格 最高价格 申请背景相关字段 20200108 start
                                                             , GuidePrice_Up__c, GuidePrice_Down__c, finalPriceDecideWay__c, mainTalksTime__c, talksStartDate__c
                                                             , Combined_rate__c, New_Contract_Type_TxT__c, Estimate_Price_range__c
                                                             //最低价格 最高价格计算 20200108 end
                                                             , Sales_incidental__c, Consumption_rate_Forecast__c, AgencyHos_Price__c
                                                             // 申请报价金额 和 相对标准价格范围的折扣率
                                                             , Request_quotation_Amount__c, Service_discount_Rate__c, ContractPriceType__c
                                                             //上限合同 20230103 hql start
                                                             ,Limit_Price_Amount__c
                                                             //上限合同 20230103 hql end
                                                             , LastMContract1__c, LastMContract2__c, LastMContract3__c, LastMContract4__c, LastMContract5__c
                                                             , LastMContract1_ConCount__c, LastMContract2_ConCount__c, LastMContract3_ConCount__c, LastMContract4_ConCount__c, LastMContract5_ConCount__c,
                                                             LastMContract1_NO__c, LastMContract2_NO__c, LastMContract3_NO__c, LastMContract4_NO__c, LastMContract5_NO__c
                                                             //跳过点检标记 2021/07/28 gzw start
                                                             , Skip_DJ__c
                                                             //跳过点检标记 2021/07/28 gzw start
                                                             // 服务合同点检拦截逻辑修改 start
                                                              ,Approved_quotation_day__c
                                                             // 服务合同点检拦截逻辑修改 end
                                                             //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220419 start
                                                             , Maintenance_Contract__r.Open_RenewalQuotation__c,Maintenance_Contract__r.VM_Contract_Check__c
                                                             //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220419 end'
                                                            //LJPH-C9SCX7 【委托】合同无空白期的提醒  lt  20211221  start
                                                             // 报价规则改善20230314 start
                                                            , Maintenance_Contract__r.Past_Contract_end_day__c //过去合同结束日
                                                            ,renewTen_OFF__c
                                                            ,AgreeRenewTen_OFF__c
                                                            ,Monthly_Repair_Cost_SUM__c
                                                             // 报价规则改善20230314 end
                                                            //LJPH-C9SCX7 【委托】合同无空白期的提醒  lt  20211221  end
                                                            // URF限次合同2期 LY 20220811 start
                                                            ,URF_P_MaxRepairCount__c,URF_V_MaxRepairCount__c
                                                            ,URFMContract1__c,URFMContract1_startDate__c,URFMContract1_endDate__c
                                                            //,URFMContract2__c,URFMContract3__c,URFMContract4__c,URFMContract5__c
                                                            ,URF_LastMContract1_NO__c,URF_LastMContract2_NO__c,URF_LastMContract3_NO__c,URF_LastMContract4_NO__c,URF_LastMContract5_NO__c
                                                            ,URF_LastMContract1_ConCount__c,URF_LastMContract2_ConCount__c,URF_LastMContract3_ConCount__c,URF_LastMContract4_ConCount__c,URF_LastMContract5_ConCount__c
                                                            // URF限次合同2期 LY 20220811 end
                                                            //故障品加费  2022/12/16 start
                                                            ,Hospital_Salesdepartment__c
                                                            ,Send_Email_To_RC__c
                                                            //故障品加费  2022/12/16 end
                                                            //贸易合规 you start
                                                            ,Maintenance_Contract__r.AccDealerBlacklist__c 
                                                            ,Maintenance_Contract__r.Hospital__r.Name
                                                            ,Maintenance_Contract__r.Dealer__r.Name
                                                            ,CreatedById
                                                            //贸易合规 you end
                                                            // 报价合并 20230602 start
                                                            ,Maintenance_Contract__r.MaintanceContractPack__r.id
                                                            // 报价合并 20230602 end
                                                            //  报价页面【合同定价总额】字段添加 20230628 start
                                                            ,Total_Contract_Price__c FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];

            //targetEstimateId blank
            Maintenance_Contract__c contract = [SELECT Id,Past_Contract_end_day__c,Estimate_Num__c FROM Maintenance_Contract__c WHERE Not_Upper_limit_reason__c = 'tect contract' LIMIT 1];
            String initResByMcid = lexSelectAssetEstimateVMController.init(contract.Id,'mcid');
            lexSelectAssetEstimateVMController.InitData transInitDataByMcid = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResByMcid, lexSelectAssetEstimateVMController.InitData.class);
            contactEsti1.Contract_Esti_Start_Date__c = Date.newInstance(2022, 2,2);
            contactEsti1.Contract_Range__c = 12;
            transInitDataByMcid.estimate = contactEsti1;
            String decideSyncEstimateResByMcid = lexSelectAssetEstimateVMController.syncEstimate(false,false,transInitDataByMcid);
            System.assertEquals(true, decideSyncEstimateResByMcid != null);
            System.Test.stopTest();
            
        }
    }
    static testMethod void testPrint() {
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];

        
        system.runAs(u3) {
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.estimate.Discount_reason__c =  'test save';
            transInitDataById.estimate.Contract_Range__c = 10;
            String printResById = lexSelectAssetEstimateVMController.print(JSON.serialize(transInitDataById));
            System.assertEquals(true, printResById != null);
            transInitDataById.estimate.Process_Status__c = '批准';
            printResById = lexSelectAssetEstimateVMController.print(JSON.serialize(transInitDataById));
            // for exc
            printResById = lexSelectAssetEstimateVMController.print('');
            System.Test.stopTest();

        }
    }
    static testMethod void testSendEmail() {
        
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id,EndUserType__c,Request_quotation_Amount__c,mainTalksTime__c,talksStartDate__c,Improve_ConsumptionRate_Idea__c,GuidePrice_Up__c
                                                             FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];


            lexSelectAssetEstimateVMController.InitData transInitDataById =  new lexSelectAssetEstimateVMController.InitData();
            transInitDataById.estimate = contactEsti1;
            transInitDataById.estimate.Discount_reason__c =  'test save';

            transInitDataById.estimate.Contract_Range__c = 10;

            transInitDataById.estimate.GuidePrice_Up__c = 0;

            transInitDataById.checkedAssets = new List<lexSelectAssetEstimateVMController.AssetInfo>();

            transInitDataById.currPage = 1;
            transInitDataById.selRecordOption = '20';
            transInitDataById.totalRecords = 0;
            transInitDataById.checkDealerId = '';
            //2021-11-30 fy add LJPH-C8W8FV 置顶 start
            transInitDataById.TopProductModel.add('CF-LV1I');
            transInitDataById.TopProductModel.add('CF-LV1L');
            transInitDataById.TopProductModel.add('CV-V1');
            transInitDataById.TopProductModel.add('GIF-LV1');
            transInitDataById.TopProductModel.add('OER-AW');
            transInitDataById.TopProductModel.add('OER-A');
            //2021-11-30 fy add LJPH-C8W8FV 置顶 end
            transInitDataById.typeresult = null;
            transInitDataById.changedAfterPrint = false;
            transInitDataById.changedSubmitPrice = false;
            transInitDataById.isSaveOrApproval = false;
            transInitDataById.OldContractStartDate = null;
            transInitDataById.OldMaintenancePrice = null;
            transInitDataById.inDicideFlag = false;
            transInitDataById.isSoft = false;
            transInitDataById.activeOn = true;
            
            //LJPH-BSS6E2  ---20200911 ---update by rentongxiao start
            transInitDataById.contr = '1';
            transInitDataById.val1 = '主机';
            transInitDataById.estimate.Contract_Esti_Start_Date__c = Date.today();
            // transInitDataById.estimate.Decided_Estimation__c ='';

            //走发邮件
            String sendEmailResById = lexSelectAssetEstimateVMController.sendEmail(JSON.serialize(transInitDataById));
            System.assertEquals(true, sendEmailResById != null);
            //验证返回结果
            transInitDataById.estimate.Contract_Range__c = null;
            sendEmailResById = lexSelectAssetEstimateVMController.sendEmail(JSON.serialize(transInitDataById));
            transInitDataById.estimate.Contract_Range__c = 10;
            transInitDataById.estimate.EndUserType__c = '';
            sendEmailResById = lexSelectAssetEstimateVMController.sendEmail(JSON.serialize(transInitDataById));

            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.estimate.Discount_reason__c =  'test save';
            transInitDataById.estimate.Contract_Range__c = 10;
            sendEmailResById = lexSelectAssetEstimateVMController.sendEmail(JSON.serialize(transInitDataById));
            System.Test.stopTest();

        }
    }
    static testMethod void testFirstPage() {
        
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            Asset objAsset = [SELECT Id, Name,OwnershipMachine_No__c,Product2.ProductURF__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c, Management_Code__c, IF_Warranty_Service__c, Reson_Can_not_Warranty__c,
                            InstallDate, isNewDate_use__c, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c, CurrentContract_End_Date__c, EquipmentGuaranteeFlg__c,
                            CurrentContract_F__c, CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.Management_Code__c, CurrentContract_F__r.RecordType_DeveloperName__c, CurrentContract_F__r.Estimate_Num__c, CurrentContract_F__r.Contract_End_Date__c, CurrentContract_F__r.Estimate_Contract_endDate__c,
                            CurrentContract_F_asset__c, CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c, CurrentContract_F_asset__r.endDateGurantee_Text__c, CurrentContract_F__r.Gurantee_Estimate_startDate__c,
                            CurrentContract_F__r.First_Estimate_Date__c,
                            //变更多年保续签开始日 thh 20220315 start
                            CurrentContract_F__r.Gurantee_Renew_startDate__c,
                            //变更多年保续签开始日 thh 20220315 end
                            //   (2022年12月上线)故障品加费 start
                            Return_Without_Repair__r.Repair_List_Price_formula__c,
                            Return_Without_Repair__r.Agreed_Date__c,
                            //   (2022年12月上线)故障品加费 end
                            CurrentContract_F__r.Contract_Consumption_rate__c, CurrentContract_F__r.First_contract_usage_Rate__c,
                            CurrentContract_F__r.Contract_Range__c, AssetMark__c,
                            //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 start
                            CurrentContract_F__r.Open_RenewalQuotation__c,CurrentContract_F__r.VM_Contract_Check__c,
                            //WLIG-CDFBV3 开通续签报价为true的可以开放续签报价 thh 20220414 end
                            // 2021-01-29 LJPH-BX9CVX mzy   add  合同报价时判断零件风险
                            NoPartRiskDate_F__c, NoPartRiskDate__c, SignableFlag__c,
                            Product2.PartSupplyFinishDate__c, Product2.PartSupplyFinishDateExp__c
                            // 2021-01-29 LJPH-BX9CVX mzy   add  合同报价时判断零件风险
                            //URF限次合同2期 LY 20220811 start
                            , URF_Maintenance_Contract__c
                            , URF_Maintenance_Contract__r.Management_Code__c
                            , URF_Maintenance_Contract__r.Contract_End_Date__c
                            //URF限次合同2期 LY 20220811 end
                            // 报价规则改善 20230315 start
                            ,IS_StandardPricing__c
                            // 报价规则改善 20230315 end
                            //多年保设备续签计算逻辑调整 2023/1/17 start
                            ,CurrentContract_F_asset__r.Asset_Consumption_Rate__c
                            ,CurrentContract_F_asset__r.Maintenance_Price_Year__c
                            ,CurrentContract_F_asset__r.IS_VMContract_Asset__c
                            ,Product2.Asset_Model_No__c
                            //  报价页面【合同定价总额】字段添加 20230608 start
                            ,Product2.Maintenance_Price_Year__c
                            //  报价页面【合同定价总额】字段添加 20230608 end
                            ,Product2.Category4__c
                            ,CurrentContract_F__r.endDateGurantee__c
                            //添加是否服务多年保修，多年保维修期至
                            ,IS_Extend_Gurantee__c,Extend_Gurantee_DateTo__c
                             //多年保设备续签计算逻辑调整 2023/1/17 end
                            FROM Asset WHERE Name = 'asset01' LIMIT 1];
            
            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.estimate.Discount_reason__c =  'test save';
            // String firstPageResById = lexSelectAssetEstimateVMController.firstPage(JSON.serialize(transInitDataById));
            // System.assertEquals(true, firstPageResById != null);
            // String nextPageResById = lexSelectAssetEstimateVMController.nextPage(JSON.serialize(transInitDataById));
            // transInitDataById.currPage++;
            // String previousPageResById = lexSelectAssetEstimateVMController.previousPage(JSON.serialize(transInitDataById));
            // String endPageResById = lexSelectAssetEstimateVMController.endPage(JSON.serialize(transInitDataById));
            // String recordNumChangeResById = lexSelectAssetEstimateVMController.recordNumChange(JSON.serialize(transInitDataById));
            Boolean getApprovalBtnNewDisabledResById = lexSelectAssetEstimateVMController.getApprovalBtnNewDisabled();
            String interceptsendResById = lexSelectAssetEstimateVMController.interceptsend(JSON.serialize(transInitDataById.estimate),transInitDataById.targetEstimateId);

            // transInitDataById.currPage = 101;
            // nextPageResById = lexSelectAssetEstimateVMController.nextPage(firstPageResById);
            System.assertEquals(true, interceptsendResById != null);
            // for exc
            interceptsendResById = lexSelectAssetEstimateVMController.interceptsend('',transInitDataById.targetEstimateId);

            System.Test.stopTest();
        }
    }
    static testMethod void testPriceChangeReset() {
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        
        system.runAs(u3) {

            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            lexSelectAssetEstimateVMController.Data dataObj = new lexSelectAssetEstimateVMController.Data(22,22,22,22);

            String initResById = lexSelectAssetEstimateVMController.init(contactEsti1.Id,'Id');
            System.assertEquals(true, initResById.length() > 0, '初始化信息异常');
            lexSelectAssetEstimateVMController.InitData transInitDataById = (lexSelectAssetEstimateVMController.InitData)JSON.deserialize(initResById, lexSelectAssetEstimateVMController.InitData.class);

            transInitDataById.estimate.Discount_reason__c =  'test save';
            transInitDataById.estimate.Contract_Range__c = 10;

            transInitDataById.changedSubmitPrice = true;
            String priceChangeResetResById = lexSelectAssetEstimateVMController.approvalProcess(JSON.serialize(transInitDataById));
            System.Test.stopTest();

        }
    }
    static testMethod void testComputeLTYRepair() {
        User u3 = [SELECT Id FROM User WHERE Username = 'olympusTest03@sunbridge.com'];
        system.runAs(u3) {
            System.Test.startTest();
            Maintenance_Contract_Estimate__c contactEsti1 = [SELECT Id FROM Maintenance_Contract_Estimate__c WHERE EndUserType__c = '既有用户' LIMIT 1];
            Account hospital =  [SELECT Id FROM Account WHERE Is_Active__c = '有效' LIMIT 1];
            Account dep = [SELECT Id FROM Account WHERE Hospital__c = :hospital.Id LIMIT 1];
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            Asset asset01 = [SELECT Id FROM Asset WHERE Name = 'asset01' LIMIT 1];
            // 修理を作成する01
            Repair__c repair01 = new Repair__c();
            repair01.Account__c = dep.Id;
            repair01.Department_Class__c = strategicDep[0].Id;
            repair01.Hospital__c = hospital.Id;
            repair01.Delivered_Product__c = asset01.Id;
            repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays(0);  // 维修合同判断日がサービス契約の中間辺りの日付
            repair01.FSE_Work_Location__c = '上海';
            repair01.AWS_Data_Id__c = '123456789';
            repair01.Agreed_Date__c = Date.today().addDays(-1);
            insert repair01;

            String computeLTYRepairResById = lexSelectAssetEstimateVMController.ComputeLTYRepair(contactEsti1.Id);
            //sumPrice  savePrintFlg  setApprovalManager
            System.assertEquals(true, computeLTYRepairResById == null);
            System.Test.stopTest();
            
        }
    }

    static testMethod void testAccSendEmailFW(){
        Maintenance_Contract__c mc = [select id,name,Hospital__r.name,
                                        Hospital__r.TradeComplianceStatus__c,
                                        Dealer__r.TradeComplianceStatus__c,
                                        Dealer__r.name,
                                        Service_Contract_Staff__r.name,
                                        Service_Contract_Staff__r.Email
                                        from Maintenance_Contract__c  limit 1];
        lexSelectAssetEstimateVMController.accSendEmailFW(mc.id,'2222222','1',null);
        lexSelectAssetEstimateVMController.accSendEmailFW(mc.id,'2222222','2','2223d2d2d');
    }

    
    
}