沙世明
2022-09-13 bfca7a84bec815da594f1d12558535ed06d2490b
force-app/main/default/classes/EquipmentRealCoverageBatch.cls
@@ -5,6 +5,7 @@
    public List<Id> conIds = new List<Id>();
    public List<Id> hospIds = new List<Id>();
    public Date toDayTime = Date.today();
    // public String type ;
    private BatchIF_Log__c iflog;
    global EquipmentRealCoverageBatch() {
@@ -13,8 +14,9 @@
        //     type = '分子';
        // }
        // if (i == 2) {
        this.query = 'select Id,(select id,IF_Coverage_Target_Asset__c,IF_Coverage_Real_Asset__c,CurrentContract__r.Contract_End_Date__c,Product2.Category4__c,Product2.ServiceCategory__c,Product2.Category3__c from Asset_Hospital__r where Status != \'廃棄\' and Status != \'待报废\''
                     +' and SerMarGuranteeType__c != \'服务多年保修\' and SerMarGuranteeType__c != \'市场多年保修\''
        this.query = 'select Id,(select id,IF_Coverage_Target_Asset__c,IF_Coverage_Real_Asset__c,CurrentContract__r.Contract_End_Date__c,CurrentContract__r.Contract_Conclusion_Date__c,Product2.Category4__c,Product2.ServiceCategory__c,Product2.Category3__c from Asset_Hospital__r where Status != \'廃棄\' and Status != \'待报废\''
                     +' and IF_Parts_production__c != \'1\' AND IF_Coverage_Target_Asset__c =\'1\''
                     +' and ((SerMarGuranteeType__c != \'服务多年保修\' and SerMarGuranteeType__c != \'市场多年保修\') or Extend_Gurantee_DateTo__c >= :egdTime)'
                     +' and Product2.ServiceCategory__c != null) from Account where id in :hospIds';
            // type = '分母';
        // }
@@ -47,6 +49,8 @@
        // }
        // if (type == '分母') {
            // 5条以上软性镜医院&&医院有效
        system.debug('执行start');
            Date egdTime = Date.newInstance(toDayTime.year()+1,3,1);
            List<AggregateResult> Asset1 = [select count(Id),Hospital__c from asset where Product2.ServiceCategory__c ='软性镜'  Group by Hospital__c having count(Id)>=5];
           if(Asset1!=null){
               for (AggregateResult a1 : Asset1) {
@@ -59,7 +63,7 @@
    }
    global void execute(Database.BatchableContext BC, list<Account> accList) {
        system.debug('执行execute');
        List<Account_Service_Of_Target__c> asotList = new List<Account_Service_Of_Target__c>();
        // if (type == '分子') {
        //     for (Account a : accList) {
@@ -102,10 +106,10 @@
                for (Asset ass1 : acc1.Asset_Hospital__r) {
                    
                    // 标记是否覆盖率目标设备
                    ass1.IF_Coverage_Target_Asset__c = '1';
                     AssetsTarget.add(ass1);
                    // ass1.IF_Coverage_Target_Asset__c = '1';
                     // AssetsTarget.add(ass1);
                    // 标记是否覆盖率实际设备
                    if (ass1.CurrentContract__r.Contract_End_Date__c >= start_dateH1 && ass1.CurrentContract__r.Contract_End_Date__c <= end_dateH1) {
                    if (ass1.CurrentContract__r.Contract_End_Date__c >= start_dateH1 && ass1.CurrentContract__r.Contract_Conclusion_Date__c <= end_dateH1) {
                        ass1.IF_Coverage_Real_Asset__c = '1';
                        AssetsReal.add(ass1);
                    }
@@ -171,14 +175,14 @@
                }
                asotList.add(asot);     
            }
        if (asotList!=null) {
            try {
                insert asotList;
            if (asotList!=null) {
                try {
                    insert asotList;
                }
                catch (Exception e) {
                    iflog.ErrorLog__c += 'ERROR'+'['+'insert asotList:'+']'+e.getMessage()+'\n';
                }
            }
            catch (Exception e) {
                iflog.ErrorLog__c += 'ERROR'+'['+'insert asotList:'+']'+e.getMessage()+'\n';
            }
        }
    }
    global void finish(Database.BatchableContext BC) {
        iflog.Log__c += '\nEquipmentRealCoverageBatch end';