public without sharing class AssetModifyBelongsChangeHandler extends Oly_TriggerHandler {
    //CHAN-B7J4SE
    private Map<Id, AssetModifyBelongsChange__c> newMap;
    private Map<Id, AssetModifyBelongsChange__c> oldMap;
    private List<AssetModifyBelongsChange__c> newList;
    private List<AssetModifyBelongsChange__c> oldList;
    private List<String> idList;
    private List<Asset> assetList;

    public AssetModifyBelongsChangeHandler(){
        this.newMap = (Map<Id, AssetModifyBelongsChange__c>) Trigger.newMap;
        this.oldMap = (Map<Id, AssetModifyBelongsChange__c>) Trigger.oldMap;
        this.newList = (List<AssetModifyBelongsChange__c>) Trigger.new;
        this.oldList = (List<AssetModifyBelongsChange__c>) Trigger.old;
        this.idList = new List<String>();
        this.assetList = new List<Asset>();
    }

    protected override void beforeUpdate(){
        updateambChange_Account();
    }
    private void updateambChange_Account() {

    	for(AssetModifyBelongsChange__c ambc :newList){
    		if(oldMap.get(ambc.Id).get('Change_status__c') != ambc.Change_status__c && ambc.Change_status__c == '批准'){
    			idList.add(ambc.Id);
    		}
    	}
        // 虚拟维修合同
        Map <string, Maintenance_Contract__c> v_MCMap = new  map <string, Maintenance_Contract__c>();
        // 虚拟维修合同对应询价名称
        Map <string, string> v_MCOppMap = new  map <string, string>();
        // 需要插入的虚拟维修合同保有设备
        List <Maintenance_Contract_Asset__c> v_MCdetinList = new  List<Maintenance_Contract_Asset__c>();
        // 需要更新的虚拟维修合同保有设备
        List <Maintenance_Contract_Asset__c> v_MCdetUpList = new  List<Maintenance_Contract_Asset__c>();
        // 新的变更合同对应的新保有设备 中间匹配用
        Map <string, List<Maintenance_Contract_Asset__c>> v_MCdetnewMap = new  map <string, List<Maintenance_Contract_Asset__c>>();

        //需要作成两个map add by rentx LJPH-C493WW  
        // 合同询价编码   维修合同/保有设备集合
        Map<String,List<Maintenance_Contract_Asset__c>> OppAssMap = new Map<String,List<Maintenance_Contract_Asset__c>>();
        // 目标客户  合同询价编码set
        Map <string, Set<Maintenance_Contract__c>> vMOppMap = new  map <string, Set<Maintenance_Contract__c>>();
        // 总院分院间调用的保有设备，变更前发送的修理要计入到变更后的合同里 thh 20220418 start
        Map<String, List<Id>> rpMcaNameMap = new Map<String, List<Id>>(); 
        Map<String, String> ChangeRepAssMap = new Map<String, String>();
        // 总院分院间调用的保有设备，变更前发送的修理要计入到变更后的合同里 thh 20220418 end

        //add by rentx LJPH-C493WW  
        //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  start
    	Map<String,Maintenance_Contract__c> MainCMap=new Map<String,Maintenance_Contract__c>();
        //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  end
        if(idList != null && idList.size() > 0){
    		
            List<AssetModifyBelongsChangeDetail__c> ambcDetailList ;
	        ambcDetailList = [select Id,Asset__c,
	        						ChangeAndChangeDetail__r.AccountField__c,
                                    ChangeAndChangeDetail__r.rawAccount__c,
                                    ChangeAndChangeDetail__r.Name,
                                    ChangeAndChangeDetail__r.ChangeReason__c
	        					from AssetModifyBelongsChangeDetail__c
	        					where ChangeAndChangeDetail__c In :idList];

            // SWAG-BCL2YW ---XHL---20190528---UpdateStart                    
            List<String> accountFieldList = new List<String>();
            // 保有设备IDlist，变更时，新建维修合同用
            Set<Id> assetidList = new Set<Id>();
            //获取目标客户的Id                    
            for (AssetModifyBelongsChangeDetail__c ambcDetail :ambcDetailList){

                accountFieldList.add(ambcDetail.ChangeAndChangeDetail__r.AccountField__c);
                // 获取变更的保有设备ID
                assetidList.add(ambcDetail.Asset__c);
            }
            Map<Id,Maintenance_Contract_Asset__c> maAssetMap = new Map<Id, Maintenance_Contract_Asset__c>();
            
            // Schema.DescribeSobjectResult d = Maintenance_Contract_Asset__c.sObjectType.getDescribe();
            // Map<String, Schema.SObjectField> fieldMap = d.fields.getMap();

            if(assetidList.size() > 0){
                for (Maintenance_Contract_Asset__c Mca :[select id,startDateGurantee__c,
                    startDateGurantee_Text__c,endDateGurantee__c,Asset__c,
                    endDateGurantee_Text__c,Return_Flag__c,ChangeAcc_flag__c,
                    Asset__r.guarantee_period__c,Asset__r.Extend_Gurantee_DateTo__c,
                    DeliveryDate__c,No_discount__c,V_MC_Name__c,Asset_SerialNumber__c,
                    //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  start
                    Maintenance_Contract__c,
                    Maintenance_Contract__r.Add_Number__c,
                    //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  end
                    Asset__r.Proviston_period__c,Maintenance_Contract__r.Management_Code__c
                    from Maintenance_Contract_Asset__c
                    where Asset__c in : assetidList
                     and Asset_Status__c = true
                    and Maintenance_Contract__r.RecordType.DeveloperName = 'VM_Contract']) {
                    maAssetMap.put(Mca.Asset__c,Mca); 
                    //add by rentx LJPH-C493WW 20210715 
                    if (!OppAssMap.containsKey(Mca.Maintenance_Contract__r.Management_Code__c)) {
                        OppAssMap.put(mca.Maintenance_Contract__r.Management_Code__c,new List<Maintenance_Contract_Asset__c>());
                    }
                    OppAssMap.get(Mca.Maintenance_Contract__r.Management_Code__c).add(Mca);
                    // Oppvmidmap.put(mca.Maintenance_Contract__r.Management_Code__c, mac.Maintenance_Contract__c);
                    //add by rentx LJPH-C493WW 20210715 

                }
            }
            System.debug('97::: OppAssMap '+OppAssMap);
            if (accountFieldList.size() > 0){

                Map<Id, Account> accMap = new Map<Id, Account>();
                List<Account> accs = ControllerUtil.selectAccountForTrigger(accountFieldList);
                
                for(Account acc : accs) {

                    accMap.put(acc.Id, acc);
                }
                // 所有客户对应的保有设备
                Map<Id,List<Maintenance_Contract_Asset__c>> changeAccMap = new Map<Id,List<Maintenance_Contract_Asset__c>>();

                for (AssetModifyBelongsChangeDetail__c ambcDetail :ambcDetailList){

                    String accountIdStr = ambcDetail.ChangeAndChangeDetail__r.AccountField__c;
                    System.debug('accountIdStr:'+ ambcDetail.ChangeAndChangeDetail__r.AccountField__c);
                    Account acc = accMap.get(accountIdStr);
                    Asset asset = new Asset();
                    //判断目标客户的类型是否是"战略科室ET"
                    if (acc != null && acc.RecordTypeId == System.Label.ET) {

                        asset.Department_Class__c = accountIdStr;
                        asset.Hospital__c = acc.ParentId;
                    } else {

                        asset.Department_Class__c = acc.ParentId;
                        asset.Hospital__c = acc.Parent.ParentId;
                    }

                    asset.Id = ambcDetail.Asset__c;
                    asset.AccountId = accountIdStr;
                    asset.rawAccounts__c = ambcDetail.ChangeAndChangeDetail__r.rawAccount__c;
                    asset.Nameno__c = ambcDetail.ChangeAndChangeDetail__c;
                    asset.ChangeReasons__c = ambcDetail.ChangeAndChangeDetail__r.ChangeReason__c;
                    assetList.add(asset);
                    // 变更虚拟维修合同信息整理 start
                    if (maAssetMap.containsKey(asset.Id)) {
                        // if (changeAccMap.containsKey(accountIdStr)) {
                        //     changeAccMap.get(accountIdStr).add(maAssetMap.get(asset.Id));
                        // }else{
                        //     List<Maintenance_Contract_Asset__c> mcatempList = new List<Maintenance_Contract_Asset__c>();
                        //     mcatempList.add(maAssetMap.get(asset.Id));
                        //     changeAccMap.put(accountIdStr,mcatempList);
                        // }
                        // if(!v_MCOppMap.containsKey(accountIdStr)){
                        //     v_MCOppMap.put(accountIdStr, maAssetMap.get(asset.Id).Maintenance_Contract__r.Management_Code__c);
                        // }

                        //update by rentx LJPH-C493WW  start
                        //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  start
                        if (!vMOppMap.containsKey(accountIdStr)) {
                            vMOppMap.put(accountIdStr, new Set<Maintenance_Contract__c>());
                            // vMOppMap.put(accountIdStr, new Set<Maintenance_Contract_Asset__c>());
                        }
                        Maintenance_Contract__c maintenancecontc=new Maintenance_Contract__c();
                        maintenancecontc.Id = maAssetMap.get(asset.Id).Maintenance_Contract__c;
                        maintenancecontc.Add_Number__c = maAssetMap.get(asset.Id).Maintenance_Contract__r.Add_Number__c;
                        maintenancecontc.Management_Code__c = maAssetMap.get(asset.Id).Maintenance_Contract__r.Management_Code__c;
                        vMOppMap.get(accountIdStr).add(maintenancecontc);
                        // vMOppMap.get(accountIdStr).add(maAssetMap.get(asset.Id));
                        //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  end
                        //update by rentx LJPH-C493WW  end
                        System.debug('maAssetMap.get(asset.Id)=====：'+maAssetMap.get(asset.Id));
                        // 总院分院间调用的保有设备，变更前发送的修理要计入到变更后的合同里 thh 20220418 start
                        if(ambcDetail.ChangeAndChangeDetail__r.ChangeReason__c == '总院分院间调用'){
                            ChangeRepAssMap.put(maAssetMap.get(asset.Id).Maintenance_Contract__r.Management_Code__c, ambcDetail.ChangeAndChangeDetail__r.ChangeReason__c);
                        }
                        // 总院分院间调用的保有设备，变更前发送的修理要计入到变更后的合同里 thh 20220418 end
                    }
                }
                System.debug('154::: vMOppMap '+vMOppMap);

                vMOppMap.remove(null);

                System.debug('156::: vMOppMap '+vMOppMap);

                //
                if (vMOppMap.size() > 0) {
                    // 总院分院间调用的保有设备，变更前发送的修理要计入到变更后的合同里 thh 20220418 start
                    List<String> mcaIdList = new List<String>();
                    Map<String, List<String>> RepairIdMap = new Map<String, List<String>>();
                    for (String accountId : vMOppMap.keySet()) {
                        System.debug('accountId1:' + accountId);
                        Set<Maintenance_Contract__c> mcSet = vMOppMap.get(accountId);
                        for(Maintenance_Contract__c mc : mcSet){
                            System.debug('ChangeRepAssMap1:' + ChangeRepAssMap);
                            System.debug('mc.Management_Code__c1:' + mc.Management_Code__c);
                            if(ChangeRepAssMap.containsKey(mc.Management_Code__c)){
                                mcaIdList.add(mc.Id);
                            }
                        }
                    }
                    System.debug('mcaIdList1:' + mcaIdList);
                    if(mcaIdList.size() > 0){
                        List<Repair__c> RepairList = [select Id, VM_Maintenance_Contract__c from Repair__c where VM_Maintenance_Contract__c	IN :mcaIdList];
                        if(RepairList.size() > 0){
                            for(Repair__c rp : RepairList){
                                List<String> newRepairIdList = new List<String>();
                                if(RepairIdMap.containsKey(rp.VM_Maintenance_Contract__c)){
                                    newRepairIdList = RepairIdMap.get(rp.VM_Maintenance_Contract__c);
                                    newRepairIdList.add(rp.Id);
                                    RepairIdMap.put(rp.VM_Maintenance_Contract__c, newRepairIdList);
                                } else{
                                    newRepairIdList.add(rp.Id);
                                    RepairIdMap.put(rp.VM_Maintenance_Contract__c, newRepairIdList);
                                }
                            }
                        }
                    }
                    // 总院分院间调用的保有设备，变更前发送的修理要计入到变更后的合同里 thh 20220418 end
                    for (String str : vMOppMap.keySet()) {
                        //update by rentx LJPH-C493WW  start
                        Set<Maintenance_Contract__c> vset = vMOppMap.get(str);
                        //Set<Maintenance_Contract_Asset__c> vset = vMOppMap.get(str);
                        //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  start
                        for (Maintenance_Contract__c mcodes : vset) {
                        //for (Maintenance_Contract_Asset__c mcodes : vset) {
                            Maintenance_Contract__c vmc = new Maintenance_Contract__c();
                            vmc.Name = accMap.get(str).Parent.Parent.Name + '多年保修';
                            vmc.Status__c = '契約';
                            system.debug('mcodes==='+mcodes);
                            // List<String> mcodestrList= mcodes.split('@');
                            // String mcode =mcodes.Maintenance_Contract__r.Management_Code__c;
                            // String mcid=(String)mcodes.Maintenance_Contract__c;
                            String mcode =mcodes.Management_Code__c;
                            String mcid=(String)mcodes.Id;
                            // String addNumber =mcodestrList[1];
                            Map<String,Decimal> addnumMap = new Map<String,Decimal>();
                            if (String.isNotBlank(mcode) && mcode.substring(mcode.length()-3,mcode.length()-2) == '-' ) {
                                String startstr = mcode.substring(0,mcode.length()-2);
                                Integer count = Integer.valueOf(mcode.substring(mcode.length()-2,mcode.length()));
                                
                                vmc.Management_CodeVM__c = startstr + String.valueOf(count +1).leftPad(2,'0');
                                // mcodes.Maintenance_Contract__r.Add_Number__c=count +1;
                                // addnumMap.put(mcid,mcodes.Maintenance_Contract__r.Add_Number__c);
                                mcodes.Add_Number__c=count +1;
                                addnumMap.put(mcid,mcodes.Add_Number__c);
                            }else{
                                    system.debug('mcodes.Maintenance_Contract__r.Add_Number__c'+mcodes.Add_Number__c);
                                    if(mcodes.Add_Number__c==null||mcodes.Add_Number__c==0){
                                    // if(mcodes.Maintenance_Contract__r.Add_Number__c==null||mcodes.Maintenance_Contract__r.Add_Number__c==0){
                                        vmc.Management_CodeVM__c = mcode + '-01';
                                        // mcodes.Maintenance_Contract__r.Add_Number__c=1;
                                        // addnumMap.put(mcid,mcodes.Maintenance_Contract__r.Add_Number__c);
                                        mcodes.Add_Number__c=1;
                                        addnumMap.put(mcid,mcodes.Add_Number__c);
                                    }else{
                                        // Decimal addnum = mcodes.Maintenance_Contract__r.Add_Number__c+1;
                                        // if(mcodes.Maintenance_Contract__r.Add_Number__c<=9){
                                        Decimal addnum = mcodes.Add_Number__c+1;
                                        if(mcodes.Add_Number__c<=9){
                                            vmc.Management_CodeVM__c = mcode + '-0'+addnum;
                                        }else{
                                            vmc.Management_CodeVM__c = mcode + '-'+addnum;
                                        }
                                        addnumMap.put(mcid,addnum);
                                    }
                                    system.debug('vmc.Management_CodeVM__c ======'+vmc.Management_CodeVM__c);
                                    system.debug('addnumMap ======'+addnumMap);
                            }
                            // 总院分院间调用的保有设备，变更前发送的修理要计入到变更后的合同里 thh 20220418 start
                            if(ChangeRepAssMap.containsKey(mcodes.Management_Code__c) && RepairIdMap.containsKey(mcodes.Id)){
                                rpMcaNameMap.put(vmc.Management_CodeVM__c, RepairIdMap.get(mcodes.Id));
                            }
                            System.debug('rpMcaNameMap====' + rpMcaNameMap);
                            // 总院分院间调用的保有设备，变更前发送的修理要计入到变更后的合同里 thh 20220418 end
                            //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  end
                            vmc.Department__c = accMap.get(str).Id;
                            vmc.Department_Class__c = accMap.get(str).ParentId;
                            vmc.Hospital__c = accMap.get(str).Parent.ParentId;
                            vmc.RecordTypeId = System.Label.VM_ContractType;
                            v_MCMap.put(mcode,vmc);

                            List<Maintenance_Contract_Asset__c> mcatempList = new List<Maintenance_Contract_Asset__c>();
                            for (Maintenance_Contract_Asset__c mac : OppAssMap.get(mcode)) {
                                Maintenance_Contract_Asset__c mactemp = mac.clone();
                                //mactemp.V_MC_Name__c = null;
                                Maintenance_Contract__c mctrobject= new Maintenance_Contract__c();
                                mactemp.Maintenance_Contract__c = null;
                                mactemp.Extend_Gurantee_DateTo__c = mac.Asset__r.Extend_Gurantee_DateTo__c;
                                mactemp.guarantee_period__c = mac.Asset__r.guarantee_period__c;
                                mactemp.Proviston_period__c = mac.Asset__r.Proviston_period__c;
                                mcatempList.add(mactemp);
                                mac.ChangeAcc_flag__c = true;
                                mac.endDateGurantee_changeAcc__c = Date.today();
                                mac.Extend_Gurantee_DateTo__c = mac.Asset__r.Extend_Gurantee_DateTo__c;
                                mac.guarantee_period__c = mac.Asset__r.guarantee_period__c;
                                mac.Proviston_period__c = mac.Asset__r.Proviston_period__c;
                                //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  start
                                mctrobject.Id=mac.Maintenance_Contract__c;
                                mctrobject.Add_Number__c=addnumMap.get(mac.Maintenance_Contract__c);
                                MainCMap.put(mctrobject.Id,mctrobject);
                                system.debug('mctrobject.Id===='+mctrobject.Id);
                                system.debug('mctrobject.Add_Number__c======='+mctrobject.Add_Number__c);
                                //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  end
                                // 给总院分院间调用的维修合同保有设备的总院分院间变更标识赋true thh 20220426 start
                                if(ChangeRepAssMap.containsKey(mac.Maintenance_Contract__r.Management_Code__c)){
                                    mac.General_Branch_Changeflag__c = true;
                                }
                                // 给总院分院间调用的维修合同保有设备的总院分院间变更标识赋true thh 20220426 end 
                                v_MCdetUpList.add(mac);
                            }
                            v_MCdetnewMap.put(mcode, mcatempList);

                        }
                        /*
                        Maintenance_Contract__c vmc = new Maintenance_Contract__c();
                        vmc.Name = accMap.get(str).Parent.Parent.Name + '多年保修';
                        vmc.Status__c = '契約';
                        String oppNostr =  v_MCOppMap.get(str);

                        if (String.isNotBlank(oppNostr) && oppNostr.substring(oppNostr.length()-3,oppNostr.length()-2) == '-' ) {
                            String startstr = oppNostr.substring(0,oppNostr.length()-2);
                            Integer count = Integer.valueOf(oppNostr.substring(oppNostr.length()-2,oppNostr.length()));
                            
                            vmc.Management_CodeVM__c = startstr + String.valueOf(count +1).leftPad(2,'0');
                        }else{
                            vmc.Management_CodeVM__c = oppNostr + '-01';
                        }
                        //vmc.Management_CodeVM__c = 'DN-' + v_MCOppMap.get(str) + '-01';
                        vmc.Department__c = accMap.get(str).Id;
                        vmc.Department_Class__c = accMap.get(str).ParentId;
                        vmc.Hospital__c = accMap.get(str).Parent.ParentId;
                        //vmc.Opportunity__c = oppMap.get(InquiryNoStr).Id;
                        vmc.RecordTypeId = System.Label.VM_ContractType;
                        v_MCMap.put(str,vmc);
                        // 更新现有维修合同保有设备
                        // 新规新的维修合同保有设备
                        List<Maintenance_Contract_Asset__c> mcatempList = new List<Maintenance_Contract_Asset__c>();
                        for (Maintenance_Contract_Asset__c mac : changeAccMap.get(str)) {
                            Maintenance_Contract_Asset__c mactemp = mac.clone();
                            //mactemp.V_MC_Name__c = null;
                            mactemp.Maintenance_Contract__c = null;
                            mactemp.Extend_Gurantee_DateTo__c = mac.Asset__r.Extend_Gurantee_DateTo__c;
                            mactemp.guarantee_period__c = mac.Asset__r.guarantee_period__c;
                            mactemp.Proviston_period__c = mac.Asset__r.Proviston_period__c;
                            mcatempList.add(mactemp);
                            mac.ChangeAcc_flag__c = true;
                            mac.endDateGurantee_changeAcc__c = Date.today();
                            mac.Extend_Gurantee_DateTo__c = mac.Asset__r.Extend_Gurantee_DateTo__c;
                            mac.guarantee_period__c = mac.Asset__r.guarantee_period__c;
                            mac.Proviston_period__c = mac.Asset__r.Proviston_period__c;
                            v_MCdetUpList.add(mac);
                        }
                        v_MCdetnewMap.put(str, mcatempList);
                        */
                        //update by rentx LJPH-C493WW  end


                    }
                    
                }
                // 变更虚拟维修合同信息整理 end
            }
            // SWAG-BCL2YW ---XHL---20190528---UpdateEnd
            
    	}

        System.debug('256::: v_MCMap '+v_MCMap);

        if (v_MCMap.size() > 0) {
            insert v_MCMap.values();
            for (String str : v_MCdetnewMap.keySet()) {
                for (Maintenance_Contract_Asset__c mca : v_MCdetnewMap.get(str)) {
                    //mca.V_MC_Name__c = v_MCMap.get(str).Name;
                    mca.Maintenance_Contract__c = v_MCMap.get(str).Id;
                    mca.startDateGurantee_changgeAcc__c = Date.today();
                    mca.ChangeAcc_flag__c = true;
                    // 给总院分院间调用的维修合同保有设备的总院分院间变更标识赋true thh 20220426 start
                    if(ChangeRepAssMap.containsKey(mca.Maintenance_Contract__r.Management_Code__c)){
                        mca.General_Branch_Changeflag__c = true;
                    }
                    // 给总院分院间调用的维修合同保有设备的总院分院间变更标识赋true thh 20220426 end 
                    v_MCdetinList.add(mca);
                }
            }
            // 总院分院间调用的保有设备，变更前发送的修理要计入到变更后的合同里 thh 20220418 Start
            List<Repair__c> updateRpList = new List<Repair__c>();
            Map<Id, Repair__c> rpMap = new Map<Id, Repair__c>();
            List<Repair__c> rpList = new List<Repair__c>();
            List<String> rpIdList = new List<String>();
            for(String str : v_MCMap.keySet()){
                Maintenance_Contract__c mc = v_MCMap.get(str);
                rpIdList = rpMcaNameMap.get(mc.Management_CodeVM__c);
            }
            if(rpIdList != null && rpIdList.size() > 0){
                rpList = [select Id, VM_Maintenance_Contract__c from Repair__c where Id IN : rpIdList];
            }
            if(rpList.size() > 0){
                for(Repair__c rp : rpList){
                    rpMap.put(rp.Id, rp);
                }
            }
            for(String str : v_MCMap.keySet()){
                Maintenance_Contract__c mc = v_MCMap.get(str);
                if(rpMcaNameMap.containsKey(mc.Management_CodeVM__c)){
                    List<String> newrpIdList = rpMcaNameMap.get(mc.Management_CodeVM__c);
                    if(newrpIdList != null && newrpIdList.size() > 0){
                        for(Id rpId : newrpIdList){
                            Repair__c rp = rpMap.get(rpId);
                            rp.VM_Maintenance_Contract__c = mc.Id;
                            updateRpList.add(rp);
                        }
                    }
                }
            }
            if(updateRpList.size() > 0){
                update updateRpList;
            }
            // 总院分院间调用的保有设备，变更前发送的修理要计入到变更后的合同里 thh 20220418 end
            // 插入变更新合同的维修合同保有设备
            insert v_MCdetinList;
            // 更新现有合同的维修合同保有设备
            update v_MCdetUpList;
            
        }
        if(assetList != null && assetList.size() > 0 ){
        	update assetList;
        }
        //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  start
        if(MainCMap != null && MainCMap.size() > 0){
            List<Maintenance_Contract__c> mainList=MainCMap.values();
            update mainList;
        }
        //LJPH-C493WW  fy	【委托】 【多年保合同】多年保设备转移造成的合同问题  end
    }


  
}