From 928399eceec50e3d37ea08669a12789a9410a9d2 Mon Sep 17 00:00:00 2001
From: 沙世明 <shashiming@prec-tech.com>
Date: 星期二, 22 十一月 2022 16:51:16 +0800
Subject: [PATCH] 111

---
 force-app/main/default/classes/OpportunityAndContactDailyUpdateBatch.cls |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/force-app/main/default/classes/OpportunityAndContactDailyUpdateBatch.cls b/force-app/main/default/classes/OpportunityAndContactDailyUpdateBatch.cls
index 10b9b86..66951b4 100644
--- a/force-app/main/default/classes/OpportunityAndContactDailyUpdateBatch.cls
+++ b/force-app/main/default/classes/OpportunityAndContactDailyUpdateBatch.cls
@@ -59,7 +59,7 @@
         system.debug(runTarget);
     }
 
-	global Database.QueryLocator start(Database.BatchableContext BC) {
+    global Database.QueryLocator start(Database.BatchableContext BC) {
         if (salesdepartment == null || salesdepartment == '') {
             query = ' select Id,FSE_Main__c,GI_Main__c,SP_Main__c,GI_Product_Leader__c,GS_Product_Leader__c,GYN_Product_Leader__c,BF_owner__c, ';
             query += 'ET_Product_Leader__c,BF_Product_Leader__c,ENT_Product_Leader__c,FSE_GI_Vice_Leader__c,FSE_SP_Vice_Leader__c,GYN_owner__c,';
@@ -98,7 +98,7 @@
          List<Account> deptClassUpdateList = [select Id, RecordType.DeveloperName, Parent.Original_Date_Flag__c, ParentId, Parent.ownerId, Parent.owner.Alias__c, OwnerId from Account where Parent.Is_Active__c = '鏈夊姽' and Parent.RecordType.DeveloperName = 'HP' and Hospital_Department_Class__c = :hpList order by Hospital_Department_Class__c, Account_Sort__c];
 
          List<Account> deptUpdateList = [select Id, RecordType.DeveloperName, Parent.Parent.Original_Date_Flag__c, Parent.owner.Alias__c, Parent.ParentId, Parent.Parent.ownerId, OwnerId from Account where Parent.Parent.Is_Active__c = '鏈夊姽' and Parent.Parent.RecordType.DeveloperName = 'HP' and Hospital__c = :hpList order by Hospital__c, Account_Sort__c];
-		 
+         
          AccountDailyUpdateBatch.updateFromHosToContact(deptUpdateList, iflog);
          updateFromHosToContact(deptUpdateList, iflog);
          //20220415 you SWAG-CBUB2W start 
@@ -111,18 +111,39 @@
     }
      //鍚屾鎵�灞炵殑璇环锛堜笟鍔℃満浼氾級鐨勬墍鏈変汉
     public static void updateFromHosToContact(List<Account> deptUpdateList, BatchIF_Log__c iflog) {
-		 List<Opportunity> updateOpportunityList =
+         List<Opportunity> updateOpportunityList =
             [select id, Ownerid, Account.ownerId from Opportunity
         where Accountid in:deptUpdateList
         and isOwnerDiffWithAccount__c = true
             AND owner_not_automatically_update__c = FALSE ];
+        //20220928 you SWAG-CJP7TL start
+        system.debug('deptUpdateList==='+deptUpdateList);
+        Map<Id,String> mapoppid = new Map<Id,String>();
         for (Opportunity opp : updateOpportunityList) {
             if (opp.Ownerid != opp.Account.ownerId) {
                 opp.Ownerid = opp.Account.ownerId;
+                mapoppid.put(opp.id,opp.Account.ownerId);
             }
         }
+        List<Task__c> taskList = [
+                SELECT Id,OpportunityId__c,taskStatus__c 
+                FROM task__c 
+                WHERE OpportunityId__c in :mapoppid.keySet()
+                AND (RecordType.Name = '涓爣缁撴灉纭' OR RecordType.Name = '澶卞崟鎶ュ憡浠诲姟')
+                AND taskStatus__c = '02 鎺ュ彈'];
+        system.debug(mapoppid.keySet()+'test1-----'+taskList);
+        for(Task__c t: taskList){
+            if(mapoppid.containsKey(t.OpportunityId__c)){
+               t.Ownerid = mapoppid.get(t.OpportunityId__c);
+               t.assignee__c = mapoppid.get(t.OpportunityId__c);
+            }
+                       
+        }    
+
         Integer indexCon = 0;
         Database.SaveResult[] lsrUpdateCon = Database.update(updateOpportunityList, false);
+        Database.SaveResult[] lsrUpdatetask = Database.update(taskList, false);
+        //20220928 you SWAG-CJP7TL end
         for (Database.SaveResult lsrChild : lsrUpdateCon) {
             if (!lsrChild.isSuccess()) {
                 iflog.Is_Error__c = 3;

--
Gitblit v1.9.1