public without sharing class TemperatureAndHumidityCheckHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; public TemperatureAndHumidityCheckHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } protected override void afterInsert() { closeTask(); } private void closeTask() { // 暂时注释,后续可能继续使用 /*List zoneList = new List(); List pick_list_values = Temperature_And_Humidity_Check__c.Temperature_And_Humidity_Zone__c.getDescribe().getPicklistValues(); for (Schema.PicklistEntry a : pick_list_values) { zoneList.add(a.getValue()); } List updTaskList = new List(); for (Temperature_And_Humidity_Check__c nObj : newList) { // 判断同备品中心是否完成所有分区的盘点 List tahcObjList = [SELECT Id, Temperature_And_Humidity_Zone__c FROM Temperature_And_Humidity_Check__c WHERE Internal_asset_location__c =: nObj.Internal_asset_location__c AND Inventory_Time__c =: nObj.Inventory_Time__c]; Map zoneMap = new Map(); for (Temperature_And_Humidity_Check__c tachObj : tahcObjList) { zoneMap.put(tachObj.Temperature_And_Humidity_Zone__c, '1'); } zoneMap.put(nObj.Temperature_And_Humidity_Zone__c, '1'); Boolean isFinished = true; for (String temp : zoneList) { if (!zoneMap.containskey(temp)) { isFinished = false; } } if (isFinished) { String roleName = null; if (nObj.Internal_asset_location__c == '北京 备品中心') { roleName = '备品中心北方管理成员'; } else if (nObj.Internal_asset_location__c == '上海 备品中心') { roleName = '备品中心华东管理成员'; } else if (nObj.Internal_asset_location__c == '广州 备品中心') { roleName = '备品中心南方管理成员'; } List taskList = [SELECT Id, taskStatus__c FROM task__c WHERE (taskStatus__c = '01 分配' OR taskStatus__c = '02 接受' OR taskStatus__c = '05 延期') AND RecordType.Name = '温湿度检查计划' AND assignee__r.RoleName_wave__c =: roleName]; for (task__c t : taskList) { t.taskStatus__c = '03 完成'; updTaskList.add(t); } } }*/ List roleNameList = new List(); for (Temperature_And_Humidity_Check__c nObj : newList) { if (nObj.Temperature_And_Humidity_Zone__c == 'A区') { String roleName = null; if (nObj.Internal_asset_location__c == '北京 备品中心') { roleName = '备品中心北方管理成员'; } else if (nObj.Internal_asset_location__c == '上海 备品中心') { roleName = '备品中心华东管理成员'; } else if (nObj.Internal_asset_location__c == '广州 备品中心') { roleName = '备品中心南方管理成员'; } if (!String.isBlank(roleName)) { roleNameList.add(roleName); } } } Date today = Date.today(); List taskList = [SELECT Id, taskStatus__c FROM task__c WHERE (taskStatus__c = '01 分配' OR taskStatus__c = '02 接受' OR taskStatus__c = '05 延期') AND RecordType.Name = '温湿度检查计划' AND assignee__r.RoleName_wave__c IN: roleNameList]; for (task__c t : taskList) { t.taskStatus__c = '03 完成'; t.Finished_Date__c = today; } if (!taskList.isEmpty()) { FixtureUtil.withoutUpdate(taskList); } } }