LLIU-CEGCRB 【委托】【新需求】产品咨询单的确认日相关
| | |
| | | if (oldMap != null && oldMap.containsKey(nnObj.Id)) { |
| | | oObj = oldMap.get(nnObj.Id); |
| | | } |
| | | if (String.isNotBlank(nnObj.Hospital_Name__c) && (Trigger.isInsert || oObj.Hospital_Name__c != nnObj.Hospital_Name__c || System.Label.Inquiry_form_flag == 'True')) { |
| | | if (String.isNotBlank(nnObj.Hospital_Name__c) && (Trigger.isInsert || oObj.Hospital_Name__c != nnObj.Hospital_Name__c)) {// || System.Label.Inquiry_form_flag == 'True') |
| | | depIDList.add(nnObj.Hospital_Name__c); |
| | | } |
| | | if (Trigger.isUpdate && String.isBlank(nnObj.Hospital_Name__c)){ |
| | |
| | | nnObj.Department_Class__c = null; //战略科室 |
| | | nnObj.HospitalName__c = null; //医院名 |
| | | nnObj.Hospital__c = null; //医院 |
| | | nnObj.CreateDate__c = null; //创建日 |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | nObj.Product1_Manual__c = ''; |
| | | //20220419 you SWAG-CBUB2W start |
| | | //公式考文本 给FSE担当赋值 |
| | | //公式考文本 给FSE担当赋值 这段必须放在这,因为新创建的数据,存在科室为空的情况, |
| | | System.debug(nObj.FSE_Owner_id__c+'==123=='+nObj.FSE_Owner__c); |
| | | if(nObj.FSE_Owner_id__c != nObj.FSE_Owner__c){ |
| | | nObj.FSE_Owner__c = nObj.FSE_Owner_id__c; |
| | | } |
| | | if(Trigger.isInsert && (nObj.Request1__c.indexOf('服务对应') !=-1 || nObj.ServiceCorrespond__c ==true)){ |
| | | if(Trigger.isInsert){ |
| | | if( nObj.Request1__c.indexOf('服务对应') !=-1 || nObj.ServiceCorrespond__c ==true){ |
| | | nObj.Service_Status__c ='01.未跟进'; |
| | | } |
| | | if(String.isBlank(nObj.Hospital_Name__c)){ |
| | | nObj.CreateDate__c = null; //创建日 |
| | | }else{ |
| | | nObj.CreateDate__c = Date.today(); |
| | | } |
| | | } |
| | | if(Trigger.isUpdate){ |
| | | |
| | |
| | | }else if( nObj.Request1__c.indexOf('服务对应') ==-1 && nObj.ServiceCorrespond__c ==false){ |
| | | nObj.Service_Status__c =''; |
| | | } |
| | | if(nObj.Hospital_Name__c != oldMap.get(nObj.Id).Hospital_Name__c && String.isBlank(oldMap.get(nObj.Id).Hospital_Name__c)){ |
| | | nObj.CreateDate__c = Date.today(); |
| | | } |
| | | //20220419 you SWAG-CBUB2W end |
| | | |
| | | //不需要日期,跟进日期,服务跟进日期,创建意向日期,比较最早日期 |
| | | String date1; |
| | | String date2; |
| | | String date3; |
| | | String date4; |
| | | if(null != nObj.No_Need_Date__c){ |
| | | date1=String.valueOf(nObj.No_Need_Date__c); |
| | | } |
| | | if(null != nObj.Follow_Date__c){ |
| | | date2=String.valueOf(nObj.Follow_Date__c); |
| | | } |
| | | if(null != nObj.Confirmation_Date__c){ |
| | | date3=String.valueOf(nObj.Confirmation_Date__c); |
| | | } |
| | | if(null != nObj.Service_Follow_Date__c){ |
| | | date4=String.valueOf(nObj.Service_Follow_Date__c); |
| | | } |
| | | |
| | | //20220419 you SWAG-CBUB2W end |
| | | //方法调用 |
| | | Date date_MD; |
| | | if((String.isNotBlank(date1) && nObj.No_Need_Date__c !=oldMap.get(nObj.Id).No_Need_Date__c) || (String.isNotBlank(date2) && nObj.Follow_Date__c !=oldMap.get(nObj.Id).Follow_Date__c) || (String.isNotBlank(date3) && nObj.Confirmation_Date__c !=oldMap.get(nObj.Id).Confirmation_Date__c) || (String.isNotBlank(date4) && nObj.Service_Follow_Date__c !=oldMap.get(nObj.Id).Service_Follow_Date__c)){ |
| | | date_MD =getBigTime(date1,date2,date3,date4); |
| | | nObj.MinimumDate__c = date_MD;//最小日期 |
| | | String date5 = nObj.CreateDate__c==null?'':String.valueOf(nObj.CreateDate__c); |
| | | if(null != nObj.CreateDate__c){ |
| | | String confdate=calendarUtil.getWorkDayNum(date5,String.valueOf(date_MD)); |
| | | //nObj.addError(s+'=='+date5+'==='+String.valueOf(date_MD)+'=='+e+'=='+confdate); |
| | | nObj.Confirmation_days__c =Integer.valueOf(confdate); |
| | | if(Integer.valueOf(confdate) > 5){ |
| | | nObj.TimeoutDays__c = Integer.valueOf(confdate)-5; |
| | | }else{ |
| | | nObj.TimeoutDays__c = null; |
| | | } |
| | | system.debug('跑这了3'); |
| | | }else{ |
| | | nObj.Confirmation_days__c = null; |
| | | nObj.TimeoutDays__c = null; |
| | | system.debug('跑这了1'); |
| | | } |
| | | |
| | | } |
| | | //处理老数据 |
| | | if( System.Label.Inquiry_form_flag == 'True' && null != nObj.CreateDate__c){ |
| | | if(String.isNotBlank(date1) || String.isNotBlank(date2) || String.isNotBlank(date3) || String.isNotBlank(date4)){ |
| | | date_MD =getBigTime(date1,date2,date3,date4); |
| | | nObj.MinimumDate__c = date_MD;//最小日期 |
| | | String date5 = nObj.CreateDate__c==null?'':String.valueOf(nObj.CreateDate__c); |
| | | String confdate=calendarUtil.getWorkDayNum(date5,String.valueOf(date_MD)); |
| | | system.debug('跑这了2'+date5+'==='+String.valueOf(date_MD)+'=='+confdate); |
| | | nObj.Confirmation_days__c =Integer.valueOf(confdate); |
| | | if(Integer.valueOf(confdate) > 5){ |
| | | nObj.TimeoutDays__c = Integer.valueOf(confdate)-5; |
| | | }else{ |
| | | nObj.TimeoutDays__c = null; |
| | | } |
| | | } |
| | | } |
| | | system.debug('==='+date_MD); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | } |
| | | //20220419 you SWAG-CBUB2W start |
| | |
| | | |
| | | } |
| | | //20220419 you SWAG-CBUB2W end |
| | | //多个日期比较最小日期 |
| | | public static Date getBigTime(String date1, String date2, String date3, String date4) { |
| | | system.debug(date1+'======'+date2+'====='+date3); |
| | | long millis1 =0; |
| | | Long millis2 =0; |
| | | Long millis3 =0; |
| | | Long millis4 =0; |
| | | List<Long> list_dateDecimal = new List<Long>(); |
| | | if(String.isNotBlank(date1)){ |
| | | millis1 = Datetime.valueOf(date1+' 08:00:05').getTime(); |
| | | list_dateDecimal.add(millis1); |
| | | } |
| | | if(String.isNotBlank(date2)){ |
| | | millis2 = Datetime.valueOf(date2+' 08:00:05').getTime(); |
| | | list_dateDecimal.add(millis2); |
| | | } |
| | | if(String.isNotBlank(date3)){ |
| | | millis3 = Datetime.valueOf(date3+' 08:00:05').getTime(); |
| | | list_dateDecimal.add(millis3); |
| | | } |
| | | if(String.isNotBlank(date4)){ |
| | | millis4 = Datetime.valueOf(date4+' 08:00:05').getTime(); |
| | | list_dateDecimal.add(millis4); |
| | | } |
| | | |
| | | list_dateDecimal.sort(); |
| | | Date date_Mid; |
| | | if(null !=list_dateDecimal && list_dateDecimal.size()>0){ |
| | | Long aaa=list_dateDecimal[0]; |
| | | DateTime dt =DateTime.newInstance(aaa); |
| | | date_Mid = dt.dateGmt(); |
| | | // DateTime.newInstance |
| | | system.debug('最小的==='+date_Mid+list_dateDecimal); |
| | | } |
| | | |
| | | return date_Mid; |
| | | |
| | | } |
| | | //俩个日期之间的工作日 |
| | | public integer diff(Datetime sdate, Datetime edate){ |
| | | integer count=0; |
| | | Date d1 = Date.valueOf(sdate); |
| | | Date d2 = Date.valueOf(edate); |
| | | integer wDay = d1.daysBetween(d2) ; |
| | | |
| | | do{ |
| | | if(sdate.format('EEEE') == 'Saturday') { |
| | | count++; |
| | | } |
| | | if(sdate.format('EEEE') == 'Sunday') { |
| | | count++; |
| | | } |
| | | sdate= sdate.adddays(1); |
| | | }while(sdate<=edate); |
| | | |
| | | wDay = wDay-count+1; |
| | | system.debug('*************'+wDay); |
| | | return wDay; |
| | | } |
| | | //客户人员录入后,【电话】【邮箱】自动录入 thh 20220321 start |
| | | // private void getContactInformation(){ |
| | | // List<String> ContactIdList = new List<String>(); |
| | |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++; |
| | | i++;//可以多写点 |
| | | } |
| | | } |
| | |
| | | ' Salesdepartment_HP__c = \'' + salesdepartment + '\''; |
| | | } |
| | | system.debug('=====query:' + query); |
| | | //Id=\'0011000000V9OGP\' and 测试用 给一条客户id |
| | | return Database.getQueryLocator(query); |
| | | |
| | | } |
| | |
| | | //20220415 you SWAG-CBUB2W start |
| | | updateFromHosToInquiryForm(deptUpdateList, iflog); |
| | | //20220415 you SWAG-CBUB2W end |
| | | |
| | | //20220509 you SWAG-CBUB2W start |
| | | //updateFromHosToInquiryFormFSEMain(hpList, iflog); |
| | | //20220509 you SWAG-CBUB2W end |
| | | } |
| | | //同步所属的询价(业务机会)的所有人 |
| | | public static void updateFromHosToContact(List<Account> deptUpdateList, BatchIF_Log__c iflog) { |
| | |
| | | //同步所属的产品咨询单的所有人 |
| | | public static void updateFromHosToInquiryForm(List<Account> deptUpdateList, BatchIF_Log__c iflog) { |
| | | List<Inquiry_form__c> updateInquiryFormList = |
| | | [select id, Ownerid, Hospital_Name__r.ownerId from Inquiry_form__c |
| | | [select id, Ownerid,Depart_Owner__c, Hospital_Name__r.ownerId from Inquiry_form__c |
| | | where Hospital_Name__c in:deptUpdateList |
| | | and isOwnerDiffWithAccount__c = true ]; |
| | | for (Inquiry_form__c ifo : updateInquiryFormList) { |
| | | if (ifo.Ownerid != ifo.Hospital_Name__r.ownerId) { |
| | | ifo.Depart_Owner__c = ifo.Hospital_Name__r.ownerId; |
| | | ifo.Ownerid = ifo.Hospital_Name__r.ownerId; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | //20220415 you SWAG-CBUB2W end |
| | | ////20220509 you SWAG-CBUB2W start |
| | | // public static void updateFromHosToInquiryFormFSEMain(List<SObject> hpList, BatchIF_Log__c iflog) { |
| | | // List<Inquiry_form__c> updateInquiryFormFSEList = |
| | | // [select id, Ownerid,Hospital_Name__c,Hospital_Name__r.Name, Hospital_Name__r.ownerId,FSE_Owner__c, |
| | | // Hospital_Name__r.Parent.Parent.FSE_GI_Main_Leader__c,Hospital_Name__r.Parent.Parent.FSE_SP_Main_Leader__c from Inquiry_form__c |
| | | // where Hospital__c in:hpList |
| | | // and isFSEDiffWithAccount__c = true ]; |
| | | // for (Inquiry_form__c ifo : updateInquiryFormFSEList) { |
| | | // if (String.isNotBlank(ifo.Hospital_Name__r.Name) && (ifo.Hospital_Name__r.Name.contains('消化') || ifo.Hospital_Name__r.Name.contains('呼吸') || ifo.Hospital_Name__r.Name.contains('ET')) && ifo.FSE_Owner__c != ifo.Hospital_Name__r.Parent.Parent.FSE_GI_Main_Leader__c) { |
| | | // ifo.FSE_Owner__c = ifo.Hospital_Name__r.Parent.Parent.FSE_GI_Main_Leader__c; |
| | | |
| | | // } |
| | | // if(String.isNotBlank(ifo.Hospital_Name__r.Name) && !ifo.Hospital_Name__r.Name.contains('消化') && !ifo.Hospital_Name__r.Name.contains('呼吸') && !ifo.Hospital_Name__r.Name.contains('ET') && ifo.FSE_Owner__c != ifo.Hospital_Name__r.Parent.Parent.FSE_SP_Main_Leader__c){ |
| | | // ifo.FSE_Owner__c = ifo.Hospital_Name__r.Parent.Parent.FSE_SP_Main_Leader__c; |
| | | // } |
| | | // } |
| | | // Integer indexCon = 0; |
| | | // Database.SaveResult[] lsrUpdateInq = Database.update(updateInquiryFormFSEList, false); |
| | | // for (Database.SaveResult lsrChild : lsrUpdateInq) { |
| | | // if (!lsrChild.isSuccess()) { |
| | | // iflog.Is_Error__c = 3; |
| | | // Database.Error emsg = lsrChild.getErrors()[0]; |
| | | // iflog.ErrorLog__c += 'ownerId: ' + updateInquiryFormFSEList.get(indexCon).ownerId + ' \n' |
| | | // + 'InquiryFormID: ' + updateInquiryFormFSEList.get(indexCon).Id + '\n ConLog:' + emsg.getMessage() + '\n'; |
| | | |
| | | // } |
| | | // indexCon ++ ; |
| | | // } |
| | | |
| | | //} |
| | | //20220509 you SWAG-CBUB2W end |
| | | global void finish(Database.BatchableContext BC) { |
| | | system.debug('=====iflog:' + iflog.id); |
| | | iflog.Log__c += 'OpportunityAndContactDailyUpdateBatch finish()\n'; |
New file |
| | |
| | | /*2022-05-13 you |
| | | * 更新产品咨询单 |
| | | * 没有确认的,确认天数=今天-创建日----自动 batch |
| | | * 有确认的(存在最小日期) 确认天数=最小日期-创建日-----触发器 |
| | | */ |
| | | global class UpdateInquiryFormConfirmationBatch implements Database.Batchable<sObject> { |
| | | public String query; |
| | | public String inqid; |
| | | private BatchIF_Log__c iflog; |
| | | |
| | | global UpdateInquiryFormConfirmationBatch() { |
| | | this.query = query; |
| | | iflog = new BatchIF_Log__c(); |
| | | iflog.Type__c = 'PushNotification'; |
| | | iflog.Is_Error__c = 0; |
| | | iflog.Log__c = 'UpdateInquiryFormConfirmationBatch start\n'; |
| | | iflog.ErrorLog__c = ''; |
| | | insert iflog; |
| | | } |
| | | |
| | | global UpdateInquiryFormConfirmationBatch(String inqid) { |
| | | this.inqid = inqid; |
| | | this.query = query; |
| | | iflog = new BatchIF_Log__c(); |
| | | iflog.Type__c = 'PushNotification'; |
| | | iflog.Is_Error__c = 0; |
| | | iflog.Log__c = 'UpdateInquiryFormConfirmationBatch start\n'; |
| | | iflog.ErrorLog__c = ''; |
| | | insert iflog; |
| | | } |
| | | |
| | | global Database.QueryLocator start(Database.BatchableContext BC) { |
| | | |
| | | query = 'select TimeoutDays__c, Id,CreateDate__c from Inquiry_form__c where CreateDate__c != null and MinimumDate__c =null'; |
| | | if (inqid != null && inqid !='') { |
| | | query += ' and id = :inqid '; |
| | | } |
| | | return Database.getQueryLocator(query); |
| | | } |
| | | |
| | | global void execute(Database.BatchableContext BC, list<Inquiry_form__c> inquiryList) { |
| | | system.debug('==='+inquiryList.size()); |
| | | String dateToday = String.valueOf(Date.today()); |
| | | for(Inquiry_form__c inq:inquiryList){ |
| | | String crdate = String.valueOf(inq.CreateDate__c); |
| | | |
| | | String confdate=calendarUtil.getWorkDayNum(crdate,dateToday); |
| | | if(Integer.valueOf(confdate) > 5){ |
| | | inq.TimeoutDays__c = Integer.valueOf(confdate)-5; |
| | | |
| | | }else{ |
| | | inq.TimeoutDays__c = null; |
| | | } |
| | | inq.Confirmation_days__c =null; |
| | | //inq.Confirmation_days__c =Integer.valueOf(confdate); |
| | | system.debug(inq.id+'=相差几天=='+confdate +'==创建日=='+crdate+'==今天=='+dateToday); |
| | | } |
| | | Integer indexCon = 0; |
| | | if(null!=inquiryList && inquiryList.size()>0){ |
| | | system.debug('inquiryList==='+inquiryList); |
| | | Database.SaveResult[] lsrUpdateCon = Database.update(inquiryList, false); |
| | | for (Database.SaveResult lsrChild : lsrUpdateCon) { |
| | | |
| | | if (!lsrChild.isSuccess()) { |
| | | iflog.Is_Error__c = 3; |
| | | Database.Error emsg = lsrChild.getErrors()[0]; |
| | | iflog.ErrorLog__c += 'confdays: ' + inquiryList.get(indexCon).TimeoutDays__c + ' \n' |
| | | + 'inquiryID: ' + inquiryList.get(indexCon).Id + '\n ConLog:' + emsg.getMessage() + '\n'; |
| | | system.debug('lsrChild.isSuccess()=='+iflog.ErrorLog__c); |
| | | } |
| | | indexCon ++ ; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | global void finish(Database.BatchableContext BC) { |
| | | system.debug('=====iflog:' + iflog.id+'==='+iflog.ErrorLog__c); |
| | | iflog.Log__c += 'UpdateInquiryFormConfirmationBatch finish()\n'; |
| | | iflog.Log__c += '\nUpdateInquiryFormConfirmationBatch end'; |
| | | |
| | | String tmp = iflog.ErrorLog__c; |
| | | if (tmp.length() > 65000) { |
| | | tmp = tmp.substring(0, 65000); |
| | | tmp += ' ...have more lines...'; |
| | | iflog.ErrorLog__c = tmp; |
| | | } |
| | | String tmp2 = iflog.Log__c; |
| | | if (tmp2.length() > 65000) { |
| | | tmp2 = tmp2.substring(0, 65000); |
| | | tmp2 += ' ...have more lines...'; |
| | | iflog.Log__c = tmp2; |
| | | } |
| | | if (System.Label.Log_IO_Flag == 'Keep') { |
| | | system.debug('jinlaile'); |
| | | update iflog; |
| | | } else if (System.Label.Log_IO_Flag == 'Auto') { |
| | | system.debug('jinlaile1'); |
| | | if (iflog.Is_Error__c > 0) { |
| | | update iflog; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>46.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
New file |
| | |
| | | @isTest |
| | | private class UpdateInquiryFormConfirmationBatchTest { |
| | | static testMethod void test_method_one() { |
| | | //医院 |
| | | List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; |
| | | if (rectHp.size() == 0) { |
| | | return; |
| | | } |
| | | //科室 |
| | | List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI']; |
| | | if (rectDpt.size() == 0) { |
| | | return; |
| | | } |
| | | |
| | | Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; |
| | | |
| | | User thisUser = [select Id from User where Id = :UserInfo.getUserId() ]; |
| | | System.runAs ( thisUser ){ |
| | | Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = thisUser.Id); |
| | | hp.FSE_GI_Main_Leader__c = thisUser.Id; |
| | | hp.FSE_SP_Main_Leader__c = thisUser.Id; |
| | | insert hp; |
| | | |
| | | //战略科室 |
| | | Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI']; |
| | | |
| | | Account dpt = new Account(RecordTypeId = rectDpt[0].Id); |
| | | dpt.Name = '*'; |
| | | dpt.Department_Name__c = 'TestDepart'; |
| | | dpt.ParentId = dc.Id; |
| | | dpt.Department_Class__c = dc.Id; |
| | | dpt.Hospital__c = hp.Id; |
| | | insert dpt; |
| | | |
| | | Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id); |
| | | dpt1.Name = '*'; |
| | | dpt1.Department_Name__c = 'TestDepart1'; |
| | | dpt1.ParentId = dc.Id; |
| | | dpt1.Department_Class__c = dc.Id; |
| | | dpt1.Hospital__c = hp.Id; |
| | | insert dpt1; |
| | | Inquiry_form__c inquiryform = new Inquiry_form__c(); |
| | | inquiryform.Name = '2019102101'; |
| | | inquiryform.Hospital_Name__c = dpt1.Id; |
| | | inquiryform.Status__c ='01.未跟进'; |
| | | inquiryform.Family_Name__c ='靳'; |
| | | inquiryform.Phone__c = '13844756322'; |
| | | inquiryform.Product1__c = '超声'; |
| | | inquiryform.Request1__c = '需要报价'; |
| | | insert inquiryform; |
| | | System.Test.startTest(); |
| | | List<Inquiry_form__c> inq = [select id,CreateDate__c,MinimumDate__c from Inquiry_form__c WHERE id = : inquiryform.Id]; |
| | | System.assertEquals(null, inq[0].MinimumDate__c); |
| | | System.assertEquals(1, inq.size()); |
| | | Id execBTId = Database.executeBatch(new UpdateInquiryFormConfirmationBatch(), 100); |
| | | System.Test.stopTest(); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>46.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
New file |
| | |
| | | public with sharing class calendarUtil { |
| | | //日期中间取日历Map |
| | | public static Map<string,OlympusCalendar__c> getCalendarMap(Date beginDate,Date endDate){ |
| | | Map<string,OlympusCalendar__c> calendarMap = new Map<string,OlympusCalendar__c>(); |
| | | List<OlympusCalendar__c> calendarList = [select id,Date__c,IsWorkDay__c from OlympusCalendar__c where Date__c >= :beginDate and Date__c <= :endDate]; |
| | | for(OlympusCalendar__c cal : calendarList){ |
| | | Date datetemp = cal.Date__c; |
| | | calendarMap.put(datetemp.format(),cal); |
| | | } |
| | | return calendarMap; |
| | | } |
| | | //获取两个日期间的工资日 |
| | | public static Integer getNumfromCalendarMap (Map<string,OlympusCalendar__c> calendarMap,Date beginDate,Date endDate){ |
| | | Integer num = 0; |
| | | List<OlympusCalendar__c> calendarList = new List<OlympusCalendar__c>(); |
| | | Set<String> keys = calendarMap.keySet(); |
| | | for(String key : keys){ |
| | | Date keyDate = Date.valueOf(key.replace('/', '-')); |
| | | if(beginDate<=keyDate && keyDate <= endDate){ |
| | | calendarList.add(calendarMap.get(key)); |
| | | } |
| | | } |
| | | for(OlympusCalendar__c oly : calendarList){ |
| | | if(oly.IsWorkDay__c == 1){ |
| | | system.debug(oly.Date__c+' '+oly.IsWorkDay__c); |
| | | num++; |
| | | } |
| | | } |
| | | |
| | | return num; |
| | | } |
| | | //获取日期num个工作日之后\之前的日期 |
| | | public static Date getCorrespondingDate(Map<String,OlympusCalendar__c> calendarMap,Date beginDate,Integer num){ |
| | | Integer count = 0; |
| | | Date temp ; |
| | | if(num > 0){ |
| | | for(Integer i = 1;;i++){ |
| | | temp = beginDate.addDays(i); |
| | | String str = temp.format(); |
| | | OlympusCalendar__c oly = calendarMap.get(str); |
| | | if(oly.IsWorkDay__c == 1){ |
| | | count++; |
| | | } |
| | | if(num == count){ |
| | | break; |
| | | } |
| | | } |
| | | }else{ |
| | | for(Integer i = -1;;i--){ |
| | | temp = beginDate.addDays(i); |
| | | String str = temp.format(); |
| | | OlympusCalendar__c oly = calendarMap.get(str); |
| | | if(oly.IsWorkDay__c == 1){ |
| | | count--; |
| | | } |
| | | if(num == count){ |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return temp; |
| | | } |
| | | |
| | | |
| | | //获取两个日期间的工资日 |
| | | public static string getWorkDayNum (String beginStr,String endStr){ |
| | | |
| | | Date beginDate = Date.valueOf(beginStr); |
| | | Date endDate = Date.valueOf(endStr); |
| | | |
| | | Map<String,OlympusCalendar__c> olmap = calendarUtil.getCalendarMap(beginDate.addDays(-1),endDate.addDays(1)); |
| | | |
| | | Integer count = calendarUtil.getNumfromCalendarMap(olmap,beginDate,endDate); |
| | | |
| | | return String.valueOf(count); |
| | | |
| | | } |
| | | //public static string getWorkDayNum (String beginStr,String endStr){ |
| | | |
| | | // Date beginDate = Date.valueOf(beginStr.replace('/', '-')); |
| | | // Date endDate = Date.valueOf(endStr.replace('/', '-')); |
| | | |
| | | // Map<String,OlympusCalendar__c> olmap = calendarUtil.getCalendarMap(beginDate.addDays(-1),endDate.addDays(1)); |
| | | |
| | | // Integer count = calendarUtil.getNumfromCalendarMap(olmap,beginDate,endDate); |
| | | |
| | | // return String.valueOf(count); |
| | | |
| | | //} |
| | | |
| | | //获取days个工作日之前或之后的日期 |
| | | public static String getWorkDay(String beginStr,String days){ |
| | | |
| | | Date beginDate = Date.valueOf(beginStr.replace('/', '-')); |
| | | Integer num = Integer.valueOf(days); |
| | | Map<String,OlympusCalendar__c> olmap = new Map<String,OlympusCalendar__c>(); |
| | | if(num<0){ |
| | | olmap = calendarUtil.getCalendarMap(beginDate.addDays(num-20),beginDate.addDays(1)); |
| | | }else{ |
| | | olmap = calendarUtil.getCalendarMap(beginDate.addDays(-1),beginDate.addDays(num+20)); |
| | | } |
| | | |
| | | Date newDate = calendarUtil.getCorrespondingDate(olmap,beginDate,num); |
| | | |
| | | return String.valueOf(newDate); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>46.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
New file |
| | |
| | | @isTest |
| | | private class calendarUtilTest { |
| | | |
| | | @isTest static void test_method_one() { |
| | | OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true); |
| | | OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true); |
| | | OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true); |
| | | OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true); |
| | | OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true); |
| | | OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false); |
| | | OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false); |
| | | OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true); |
| | | OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true); |
| | | OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true); |
| | | OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true); |
| | | OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true); |
| | | |
| | | insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12}; |
| | | |
| | | Map<String,OlympusCalendar__c> calMap = calendarUtil.getCalendarMap(Date.today().addDays(1),Date.today().addDays(12)); |
| | | |
| | | Integer count = calendarUtil.getNumfromCalendarMap(calMap,Date.today().addDays(3),Date.today().addDays(8)); |
| | | |
| | | system.debug(calMap); |
| | | system.debug(count); |
| | | |
| | | Date beforeDate = calendarUtil.getCorrespondingDate(calMap,Date.today().addDays(6),2); |
| | | Date afterDate = calendarUtil.getCorrespondingDate(calMap,Date.today().addDays(6),-2); |
| | | system.debug(beforeDate+'======'+afterDate); |
| | | |
| | | String workdayNum = calendarUtil.getWorkDayNum(String.valueOf(Date.today().addDays(3)),String.valueOf(Date.today().addDays(8))); |
| | | //String workdayNum = calendarUtil.getWorkDayNum(Date.today().addDays(3),Date.today().addDays(8)); |
| | | String workday = calendarUtil.getWorkDay(String.valueOf(Date.today().addDays(3)),'5'); |
| | | String workday1 = calendarUtil.getWorkDay(String.valueOf(Date.today().addDays(3)),'-1'); |
| | | system.debug(workday+'===='+workdayNum+'====='+workday1); |
| | | |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>46.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |