public without sharing class TaskTriggerHandler {
   
     public static String recordtypeId = '';
    public static void CreateCase(List<Task> newList, Map<Id, Task> newMap, List<Task> oldList, Map<Id, Task> oldMap) {
        recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Case' and DeveloperName = 'Draft'].id;
        List<Case> upsertCaseList = new List<Case>();
        for (Task newTask : newList) {
            Task oldServiceSummary = oldMap == null ? null : oldMap.get(newTask.Id);
            if (oldServiceSummary != null) {
                if (newTask.IndividualCase__c != oldServiceSummary.IndividualCase__c && newTask.IndividualCase__c) {
                    upsertCaseList.add(CaseDate(newTask));
                }
            } else  if (newTask.IndividualCase__c) {
                upsertCaseList.add(CaseDate(newTask));
            }
            
        }

        if (upsertCaseList.size() > 0 ) {
            upsert upsertCaseList;
        }

    }


    public static Case CaseDate(Task task) {

        Case newCase = new Case();
        newCase.Subject = task.ServiceSubject__c; //主题 
        newCase.Description = task.Description; //描述
        // newCase.AccountId = task.ServiceAccount__c; //服务客户
        newCase.Reason = task.ServiceReason__c; //个案原因
        newCase.Origin = task.ServiceOrigin__c; //个案来源
        newCase.Priority = task.Priority; //优先级
        newCase.CreatedDate = Datetime.now(); //开始日期/时间
        // newCase.CaseServiceSummary__c = task.Id;
        newCase.Status = 'New';
        newCase.ApprovalStatus__c = '草案中';
        newCase.recordtypeId = recordtypeId;

        return newCase;
    } 
}