/**
|
* Created by T on 2020/5/21.
|
*/
|
|
@IsTest
|
private class MonthEndAutoJudgeScheduleTest {
|
|
//CHAN-BUZC7V update by rentx 2020-11-05 start
|
@IsTest(SeeAllData=true)
|
static void test(){
|
String CRON_EXP = '00 0 0 3 9 ? 2022';
|
System.Test.startTest();
|
// Schedule the test job
|
String jobId = system.schedule('MonthEndAutoJudgeScheduleTest', CRON_EXP, new MonthEndAutoJudgeSchedule());
|
System.Test.stopTest();
|
}
|
|
//CHAN-BUZC7V update by rentx 2020-11-05 end
|
|
/**
|
static testMethod void testExecute() {
|
|
// 本月最后五个工作日最小的那个
|
// Date OlympusCalendarDate1 = Date.newInstance(2020,5,25);
|
Date OlympusCalendarDate1 = Date.newInstance(2020,6,30);
|
OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = OlympusCalendarDate1);
|
// 本月第一个工作日
|
Date OlympusCalendarDate2 = Date.newInstance(2020,6,1);
|
//Date OlympusCalendarDate2 = Date.newInstance(Date.today().year(),Date.today().month(),1);
|
OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = OlympusCalendarDate2);
|
insert new OlympusCalendar__c[] {oc1,oc2};
|
|
|
// This test runs a scheduled job at midnight Sept. 3rd. 2022
|
String CRON_EXP = '00 0 0 3 9 ? 2022';
|
|
System.Test.startTest();
|
// Schedule the test job
|
String jobId = system.schedule('MonthEndAutoJudgeScheduleTest', CRON_EXP, new MonthEndAutoJudgeSchedule());
|
// Get the information from the CronTrigger API object
|
CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
|
// Verify the expressions are the same
|
System.assertEquals(CRON_EXP, ct.CronExpression);
|
// Verify the job has not run
|
System.assertEquals(0, ct.TimesTriggered);
|
// Verify the next time the job will run
|
System.assertEquals('2022-09-03 00:00:00', String.valueOf(ct.NextFireTime));
|
System.debug('ct.NextFireTime:' + String.valueOf(ct.NextFireTime));
|
}
|
*/
|
// @IsTest(SeeAllData=true)
|
// static void test() {
|
//
|
// String queryStr = 'SELECT Id,Name,Consumable_order_minor__c,Consumable_Arrived_order__c,' +
|
// ' Intra_Trade_List_RMB__c,Agencyinfo_fromSAP__c,Frist_Storage_Agency__c,' +
|
// ' Dealer_Info_text__c,Asset_Model_No__c,SerialLotNo__c,Bar_Code__c,TracingCode__c,' +
|
// ' Deliver_date__c,Arrive_date__c,Direct_Arrive_Product__c,Dealer_Arrive__c,Dealer_Shipment__c,' +
|
// ' Dealer_Saled__c,Dealer_Returned__c,Lose_Flag__c,SummonsForDirction_det__c' +
|
// ' FROM Consumable_order_details2__c' +
|
// ' WHERE (not Dealer_Info_text__c like \'%TEST%\')' +
|
// ' AND TracingCode__c != \'\'' +
|
// ' AND Dealer_Arrive__c = true' +
|
// ' AND Frist_Storage_Agency__c = \'\'' +
|
// ' AND Consumable_order_minor__c != \'\'';
|
//
|
// // 获取所有需要修改的数据
|
// List<Consumable_order_details2__c> codcs = Database.query(queryStr);
|
// // key:管理编号 value:同一管理编号的数据
|
// Map<String, List<Consumable_order_details2__c>> maps = new Map<String, List<Consumable_order_details2__c>>();
|
//
|
// for (Consumable_order_details2__c cod : codcs) {
|
// // 拿到同一编号的集合
|
// List<Consumable_order_details2__c> cos = [
|
// SELECT Id,Name,Consumable_order_minor__c
|
// FROM Consumable_order_details2__c
|
// WHERE TracingCode__c = :cod.TracingCode__c
|
// ];
|
// // 将编号和对应的数据集合添加的map集合中
|
// maps.put(cod.TracingCode__c, cos);
|
// }
|
//
|
// // 迭代数据进行修改
|
// for (String str : maps.keySet()) {
|
// // 获取每个管理编号对应的数据
|
// List<Consumable_order_details2__c> cos = maps.get(str);
|
// System.debug('str' + str);
|
// System.debug('cos' + cos);
|
// System.debug('===============');
|
//
|
// // 迭代每组需要修改的数据
|
// for (Consumable_order_details2__c cod : cos) {
|
//
|
// }
|
//
|
// }
|
//
|
// }
|
//
|
// static void test222() {
|
//
|
// // 需要修改的数据
|
//// List<String> coms = new List<String>();
|
//// coms.add('XB-151P-05-S38788');
|
//
|
// // 获取所有消耗品订单不为空的字段
|
// List<Consumable_order_details2__c> lists = [
|
// SELECT Id, Name,Consumable_order_minor__r.Name
|
// FROM Consumable_order_details2__c
|
// WHERE
|
// (not Dealer_Info_text__c like '%TEST%' ) AND TracingCode__c != '' AND Dealer_Arrive__c = true AND Frist_Storage_Agency__c = '' and Consumable_order_minor__c != ''
|
// ];
|
// // 将消耗品订单的值存到set集合中,批量执行
|
// Set<String> coms = new Set<String>();
|
// for (Consumable_order_details2__c consumable_order_details2 : lists) {
|
// coms.add(consumable_order_details2.Consumable_order_minor__r.Name);
|
// }
|
//
|
// // 查出所有直接入库为true的数据
|
// List<Consumable_order_details2__c> cods = [
|
// SELECT Id, Name,Consumable_order_minor__c,Consumable_Arrived_order__c,Intra_Trade_List_RMB__c,Agencyinfo_fromSAP__c,Frist_Storage_Agency__c,Dealer_Info_text__c,Asset_Model_No__c,SerialLotNo__c,Bar_Code__c,TracingCode__c,Deliver_date__c,Arrive_date__c,Direct_Arrive_Product__c,Dealer_Arrive__c,Dealer_Shipment__c,Dealer_Saled__c,Dealer_Returned__c,Lose_Flag__c,SummonsForDirction_det__c
|
// FROM Consumable_order_details2__c
|
// WHERE
|
// (not Dealer_Info_text__c like '%TEST%' ) AND TracingCode__c != '' AND Dealer_Arrive__c = true AND Frist_Storage_Agency__c = '' AND Consumable_order_minor__r.Name IN :coms
|
// AND Direct_Arrive_Product__c = true
|
// ];
|
//
|
// // 保存所有数据的管理编号
|
// List<String> tracingCodes = new List<String>();
|
// for (Consumable_order_details2__c cod : cods) {
|
// tracingCodes.add(cod.TracingCode__c);
|
//
|
//// 修改
|
//// 首次入库经销商 = SAP发货经销商
|
// cod.Frist_Storage_Agency__c = cod.Agencyinfo_fromSAP__c;
|
//// 取消直接入库勾选
|
// cod.Direct_Arrive_Product__c = false;
|
//// 勾选IF情报元
|
// cod.IF_Information_From__c = true;
|
// }
|
//
|
// // 根据管理编号查询出所有需要删除的数据
|
// List<Consumable_order_details2__c> delCods = [
|
// SELECT Id, Name,TracingCode__c,Bar_Code__c
|
// FROM Consumable_order_details2__c
|
// WHERE Consumable_order_minor__r.Name IN :coms
|
// AND TracingCode__c IN :tracingCodes
|
// AND Dealer_Arrive__c = false
|
// ];
|
// System.debug('delCods' + delCods);
|
//
|
// // 删除多余的数据
|
// delete delCods;
|
// System.debug('cods' + cods.size());
|
// // 存储需要更改的数据
|
// List<Consumable_order_details2__c> updates2 = new List<Consumable_order_details2__c>();
|
// tracingCodes = new List<String>();
|
// for (Consumable_order_details2__c cod : cods) {
|
// tracingCodes.add(cod.TracingCode__c);
|
// }
|
//
|
// // 查询删除一部分数据后仍需更改的另一部分数据 管理编号相同
|
// List<Consumable_order_details2__c> cods2 = [
|
// SELECT Id, Name,TracingCode__c,Bar_Code__c,Frist_Storage_Agency__c,Agencyinfo_fromSAP__c
|
// FROM Consumable_order_details2__c
|
// WHERE TracingCode__c IN :tracingCodes
|
// ];
|
//
|
// for (Consumable_order_details2__c details2 : cods2) {
|
// // 如果首次入货经销商没有值并且不是初始中需要更改的数据 添加到updates2中
|
// if (String.isBlank(details2.Frist_Storage_Agency__c)) {
|
// boolean flag = true;
|
// for (Consumable_order_details2__c consumable_order_details2 : cods) {
|
// if (consumable_order_details2.Id == details2.Id) {
|
// flag = false;
|
// break;
|
// }
|
// }
|
// if (flag) {
|
// details2.Frist_Storage_Agency__c = details2.Agencyinfo_fromSAP__c;
|
// updates2.add(details2);
|
// }
|
// }
|
// }
|
//
|
// // 将updates2中的数据添加到cods中 一起更新
|
// cods.addAll(updates2);
|
// System.debug('update.size()' + cods.size());
|
// update cods;
|
// }
|
//
|
//
|
// static void testaaq() {
|
//
|
// // 获取所有消耗品订单不为空的字段
|
// List<Consumable_order_details2__c> lists = [
|
// SELECT Id, Name,Consumable_order_minor__r.Name
|
// FROM Consumable_order_details2__c
|
// WHERE
|
// (not Dealer_Info_text__c like '%TEST%' ) AND TracingCode__c != '' AND Dealer_Arrive__c = true AND Frist_Storage_Agency__c = '' and Consumable_order_minor__c != ''
|
// ];
|
// // 将消耗品订单的值存到set集合中,批量执行
|
// Set<String> coms = new Set<String>();
|
// for (Consumable_order_details2__c consumable_order_details2 : lists) {
|
// coms.add(consumable_order_details2.Consumable_order_minor__r.Name);
|
// }
|
//
|
//// for (Consumable_order_details2__c consumable_order_details2 : lists) {
|
//// coms.add(consumable_order_details2.Consumable_order_minor__r.Name);
|
//// }
|
//// coms.add('DB-151P-04-S32242');
|
//
|
// List<Consumable_order_details2__c> cods = [
|
// SELECT Id, Name,Consumable_order_minor__c,Consumable_Arrived_order__c,Intra_Trade_List_RMB__c,Agencyinfo_fromSAP__c,Frist_Storage_Agency__c,Dealer_Info_text__c,Asset_Model_No__c,SerialLotNo__c,Bar_Code__c,TracingCode__c,Deliver_date__c,Arrive_date__c,Direct_Arrive_Product__c,Dealer_Arrive__c,Dealer_Shipment__c,Dealer_Saled__c,Dealer_Returned__c,Lose_Flag__c,SummonsForDirction_det__c
|
// FROM Consumable_order_details2__c
|
// WHERE
|
// (not Dealer_Info_text__c like '%TEST%' ) AND TracingCode__c != '' AND Dealer_Arrive__c = true AND Frist_Storage_Agency__c = '' AND Consumable_order_minor__r.Name IN :coms
|
// AND Dealer_Arrive__c= true
|
// ];
|
//
|
// Set<String> tracingCodes = new Set<String>();
|
// for (Consumable_order_details2__c consumable_order_details2 : cods) {
|
// consumable_order_details2.Frist_Storage_Agency__c = consumable_order_details2.Agencyinfo_fromSAP__c;
|
// tracingCodes.add(consumable_order_details2.TracingCode__c);
|
// }
|
//
|
// List<Consumable_order_details2__c> dels = [
|
// SELECT Id, Name,Consumable_order_minor__c,Consumable_Arrived_order__c,Intra_Trade_List_RMB__c,Agencyinfo_fromSAP__c,Frist_Storage_Agency__c,Dealer_Info_text__c,Asset_Model_No__c,SerialLotNo__c,Bar_Code__c,TracingCode__c,Deliver_date__c,Arrive_date__c,Direct_Arrive_Product__c,Dealer_Arrive__c,Dealer_Shipment__c,Dealer_Saled__c,Dealer_Returned__c,Lose_Flag__c,SummonsForDirction_det__c
|
// FROM Consumable_order_details2__c
|
// WHERE Consumable_order_minor__r.Name IN :coms
|
// AND TracingCode__c = :tracingCodes
|
// AND Dealer_Arrive__c = false
|
// ];
|
//
|
// update cods;
|
// delete dels;
|
//
|
//
|
//
|
// }
|
|
}
|