global class MaintenanceContractWebService {
|
// 用户点击上传sap按钮,更新状态到契约,自动触发上传sap接口程序
|
WebService static String up2sap(String mcid) {
|
List<Maintenance_Contract__c> mcList = [select id, Status__c, Maintenance_Contract_No__c , Hospital__c , RecordTypeId, RecordType.DeveloperName,Is_RecognitionModel__c,Recognition_Model_Type__c,upload_to_RM_time__c,old_Is_RecognitionModel__c,Is_Recognition_Model_True__c from Maintenance_Contract__c where id = :mcid ];
|
if (mcList.size() == 0) {
|
return '维修合同不存在,请确认维修合同ID。';
|
}
|
Maintenance_Contract__c mc = mcList[0];
|
if (mc.Maintenance_Contract_No__c == null || mc.Maintenance_Contract_No__c == '') {
|
return Schema.SObjectType.Maintenance_Contract__c.fields.Maintenance_Contract_No__c.label + '为空,不能上传sap';
|
}
|
//update wangweipeng 2021/11/17 start
|
//用于判断当前合同是否需要认款
|
boolean flag = false;
|
//判断是否需要认款合同
|
if(mc.old_Is_RecognitionModel__c){
|
//判断当前合同是否已经认款完成
|
if(!mc.Is_Recognition_Model_True__c){
|
flag = true;
|
}
|
}
|
//update wangweipeng 2021/11/17 end
|
try {
|
if(flag){
|
mc.upload_to_RM_time__c = Datetime.now();//上传认款合同时间
|
//mc.old_Is_RecognitionModel__c = mc.Is_RecognitionModel__c;
|
}else{
|
mc.Status__c = '契約';
|
mc.upload_to_sap_time__c = Datetime.now();
|
|
//2021-01-14 mzy add LJPH-BWY5QB 合同状态为合同中时 ,将客户上的 维修合同用户类型 设为true ,合同上的 用户类型 为 新用户, 以后维修合同用户类型 都为 true 合同上的 用户类型 为 既有用户
|
//只有合同是维修合同和服务合同的时候进入
|
if (!mc.RecordType.DeveloperName.equals('VM_Contract')) {
|
List<Account> acList = [select id, MaintenanceContractUserType__c from Account where id = :mc.Hospital__c];
|
if (acList != null && acList.size() > 0) {
|
Account hp = acList[0];
|
//老用户
|
if (hp.MaintenanceContractUserType__c == true) {
|
mc.UserType__c = '既有用户';
|
} else {
|
//新用户
|
hp.MaintenanceContractUserType__c = true;
|
mc.UserType__c = '新用户';
|
update hp;
|
}
|
}
|
}
|
}
|
update mc;
|
//2021-01-14 mzy add LJPH-BWY5QB 合同状态为合同中时 ,将客户上的 维修合同用户类型 设为true ,合同上的 用户类型 为 新用户, 以后维修合同用户类型 都为 true 合同上的 用户类型 为 既有用户
|
} catch (Exception ex) {
|
return ex.getMessage();
|
}
|
|
return '1';
|
}
|
// fxk 点击上传SAP按钮自动生成点检计划 2021/7/22 Start
|
WebService static String Check_plan(List<String> mcidList) {
|
System.debug('1234567890');
|
List<Maintenance_Contract__c> MCList = [select Id, Contract_Start_Date__c, Service_contract_target_number__c,
|
Actual_Execution_Quantity_Summary__c,
|
//2021-09-08 mzy FSE分批点检如果有遗漏设备的提醒设置 设置点检计划的合同担当 start
|
Service_Contract_Staff__c,Contract_Range__c,Contract_Period__c,
|
//2021-09-08 mzy FSE分批点检如果有遗漏设备的提醒设置 设置点检计划的合同担当 end
|
Contract_End_Date__c, Inspection_Time__c
|
from Maintenance_Contract__c where Id in: mcidList];
|
|
// Inspection_Report__c CheckPlanR = [select Id, Inspection_asset_number__c, Approved_date__c,
|
// Failourassetnumber__c
|
// from Inspection_Report__c where Contract__c = : mcid];
|
// Inspection_Item__c CheckPlanI = [select Id, ItemStatus__c, Failourassetnumber__c
|
// from Inspection_Item__c where Maintance_Static_His__c = : mcid];
|
System.debug('MCInfoList:' + MCList);
|
// 存新创建的点检计划
|
List<Inspectup_Plan__c> IPInfoList = new List<Inspectup_Plan__c>();
|
// 1.合同总月数
|
// 2.合同总点检次数
|
// 3.每次点检月份区间
|
// 遍历总月数{
|
// 满一年点检日期区间
|
// 不满一年点检日期区间
|
// // 总年数
|
// Integer Allyear = Integer.valueOf(PageMCEElement.Contract_End_Date__c.year() - PageMCEElement.Contract_Start_Date__c.year());
|
// System.debug('Zongnianshu' + Allyear);
|
// // 剩余月数
|
// Integer RestMonth = Integer.valueOf(PageMCEElement.Contract_End_Date__c.month() - PageMCEElement.Contract_Start_Date__c.month());
|
// // 剩余月应该点检的次数
|
// Integer RestMonth_check = RestMonth / (12 / Integer.valueOf(PageMCEElement.Inspection_Time__c));
|
// // 合同点检总次数
|
// Integer All_check = Allyear * Integer.valueOf(PageMCEElement.Inspection_Time__c) + RestMonth_check;
|
// 总点检次数
|
// Integer All_check;
|
//合同总月数
|
// Integer Contract_validMonth;
|
// Integer CheckPlan;
|
Map<Id, Integer> MCTOCheckMap = new Map<Id, Integer>();
|
for (Maintenance_Contract__c Mc : MCList) {
|
Integer All_check = 0;
|
if (MC.Inspection_Time__c != null && MC.Inspection_Time__c != '') {
|
Integer CheckPlan = Integer.valueOf(MC.Inspection_Time__c);
|
//合同总月数
|
Integer Contract_validMonth = Integer.valueOf(MC.Contract_Range__c);
|
// add 一年内点检区间不够生成一次点检计划,默认生成一个点检计划,计划区间为合同开始日-结束日 2021/10/25 fxk Star
|
if((CheckPlan == 1 && Contract_validMonth < 9)
|
|| (CheckPlan == 2 && Contract_validMonth < 6)
|
|| (CheckPlan == 3 && Contract_validMonth < 4)
|
|| (CheckPlan == 4 && Contract_validMonth < 3)){
|
All_check = 1;
|
}else{
|
// add 一年内点检区间不够生成一次点检计划,默认生成一个点检计划,计划区间为合同开始日-结束日 2021/10/25 fxk end
|
if (Contract_validMonth - Integer.valueOf(Contract_validMonth / 12) * 12 >= 6 && CheckPlan == 1) {
|
All_check = (Contract_validMonth * Integer.valueOf(MC.Inspection_Time__c)) / 12 + 1;
|
} else {
|
All_check = (Contract_validMonth * Integer.valueOf(MC.Inspection_Time__c)) / 12;
|
}
|
System.debug('-------Contract_validMonth:' + Contract_validMonth);
|
}
|
MCTOCheckMap.put(Mc.Id, All_check);
|
}
|
}
|
|
// 合同点检总次数
|
Map<Integer, List<Integer>> tempMapCheck = new Map<Integer, List<Integer>>();
|
// 如果签一年合同有效期不是(1-12月)则它的点检的月份应为(点检次数为1)
|
// Integer[] a1 = new Integer[] {9};
|
// Integer[] a2 = new Integer[] {6};
|
// Integer[] a3 = new Integer[] {4};
|
// Integer[] a4 = new Integer[] {3};
|
|
List<Integer> checkMonth = new List<Integer> {0, 9, 6, 4, 3};
|
|
// tempMapCheck.put(1, a1);
|
// tempMapCheck.put(2, a2);
|
// tempMapCheck.put(3, a3);
|
// tempMapCheck.put(4, a4);
|
// gzw 计数初始化
|
// Integer nameNo = 0;
|
try {
|
for (Maintenance_Contract__c Mc : MCList) {
|
// gzw 计数初始化
|
Integer nameNo = 0;
|
if (MC.Inspection_Time__c != null && MC.Inspection_Time__c != '') {
|
// 总点检次数
|
Integer All_check = 0;
|
if (MCTOCheckMap.containsKey(Mc.Id)) {
|
All_check = MCTOCheckMap.get(Mc.Id);
|
}
|
// 年点检次数
|
Integer CheckPlan = Integer.valueOf(MC.Inspection_Time__c);
|
//合同总月数
|
//update 2021/11/11 fxk star
|
Integer Contract_validMonth = Integer.valueOf(MC.Contract_Period__c);
|
//Integer Contract_validMonth = MC.Contract_Start_Date__c.monthsBetween(MC.Contract_End_Date__c);
|
//update 2021/11/11 fxk end
|
for (Integer i = 1; i <= All_check; i++ ) {
|
|
if (i * 12 <= Contract_validMonth) {
|
if (CheckPlan == 1) {
|
Integer keys = checkMonth[CheckPlan];
|
System.debug('------3-------' + keys);
|
// for (Integer keys : tempMapCheck.get(CheckPlan)) {
|
for (Integer j = 1; j <= CheckPlan; j++ ) {
|
System.debug('------5-------' + i);
|
// Integer keys = checkMonth[CheckPlan]
|
Integer keys1 = checkMonth[CheckPlan];
|
System.debug('------4-------' + keys1);
|
// 计划开始日
|
Date startDate;
|
Date endDate;
|
Date taskTime;
|
// if (Contract_validMonth <= 12) {
|
// startDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + (keys - keys1));
|
// taskTime = startDate.addMonths(5);
|
// }else
|
if(i>1){
|
startDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + (keys - keys1)-3);
|
taskTime = startDate.addMonths(8);
|
}else{
|
startDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + (keys - keys1));
|
taskTime = startDate.addMonths(5);
|
}
|
|
System.debug('------1-------' + startDate);
|
// 计划结束日
|
endDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + keys).addDays(-1);
|
System.debug('------2-------' + endDate);
|
keys += keys1;
|
System.debug('------6-------' + keys);
|
//防止点检计划结束日大于合同结束日
|
if (endDate > MC.Contract_End_Date__c ) {
|
endDate = MC.Contract_End_Date__c;
|
}
|
nameNo++;
|
//2021-09-02 mzy update start
|
//发送任务的日期改成跟着实施期限的日期和合同期限的日期走,不要是固定的那个月的1号
|
//Date taskTime = Date.newInstance(endDate.year(), endDate.month() - 1, 1);
|
//如果是1年点检1次的话则是合同开始日+5个月
|
// Date taskTime = endDate.addMonths(-1);
|
// if (CheckPlan == 1) {
|
//taskTime = MC.Contract_Start_Date__c.addMonths(5);
|
|
// }
|
//2021-09-02 mzy update end
|
System.debug('1234567890:' + nameNo);
|
planInfo(IPInfoList, nameNo, MC, startDate, endDate, taskTime);
|
}
|
} else {
|
Integer keys = checkMonth[CheckPlan];
|
System.debug('------3-------' + keys);
|
// for (Integer keys : tempMapCheck.get(CheckPlan)) {
|
for (Integer j = 1; j <= CheckPlan; j++ ) {
|
System.debug('------5-------' + i);
|
// Integer keys = checkMonth[CheckPlan]
|
Integer keys1 = checkMonth[CheckPlan];
|
System.debug('------4-------' + keys1);
|
// 计划开始日
|
Date startDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + (keys - keys1));
|
System.debug('------1-------' + startDate);
|
// 计划结束日
|
Date endDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + keys).addDays(-1);
|
System.debug('------2-------' + endDate);
|
keys += keys1;
|
System.debug('------6-------' + keys);
|
//防止点检计划结束日大于合同结束日
|
if (endDate > MC.Contract_End_Date__c ) {
|
endDate = MC.Contract_End_Date__c;
|
}
|
nameNo++;
|
//2021-09-02 mzy update start
|
//发送任务的日期改成跟着实施期限的日期和合同期限的日期走,不要是固定的那个月的1号
|
//Date taskTime = Date.newInstance(endDate.year(), endDate.month() - 1, 1);
|
//如果是1年点检1次的话则是合同开始日+5个月
|
Date taskTime = endDate.addMonths(-1);
|
// if (CheckPlan == 1) {
|
// //taskTime = MC.Contract_Start_Date__c.addMonths(5);
|
// taskTime = startDate.addMonths(5);
|
// }
|
//2021-09-02 mzy update end
|
System.debug('1234567890:' + nameNo);
|
planInfo(IPInfoList, nameNo, MC, startDate, endDate, taskTime);
|
}
|
}
|
} else {
|
// 剩余月份应该点检的次数
|
Integer num;
|
if (CheckPlan == 1) {
|
System.debug('-------2-----' + CheckPlan);
|
if ((Contract_validMonth - (i - 1) * 12) >= 6 ) {
|
System.debug('--------1--------' + (Contract_validMonth - (i - 1) * 12));
|
num = 1;
|
for (Integer j = 0 ; j < num ; j++) {
|
Integer keys = checkMonth[CheckPlan];
|
Date startDate;
|
if (Contract_validMonth < 12) {
|
startDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + (keys * j));
|
}else{
|
startDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + (keys * j) - 3);
|
}
|
// Date endDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + (keys1 + keys1 * j)).addDays(-1);
|
Date endDate = MC.Contract_End_Date__c;
|
nameNo++;
|
//2021-09-02 mzy update start
|
//发送任务的日期改成跟着实施期限的日期和合同期限的日期走,不要是固定的那个月的1号
|
//Date taskTime = Date.newInstance(MC.Contract_End_Date__c.year(), MC.Contract_End_Date__c.month() - 2, 1);
|
Date taskTime = MC.Contract_End_Date__c.addMonths(-2);
|
//2021-09-02 mzy update end
|
planInfo(IPInfoList, nameNo, MC, startDate, endDate, taskTime);
|
}
|
}
|
// add 一年内点检区间不够生成一次点检计划,默认生成一个点检计划,计划区间为合同开始日-结束日 2021/10/25 fxk Star
|
if ( Contract_validMonth < 6 ) {
|
Date startDate = MC.Contract_Start_Date__c;
|
Date endDate = MC.Contract_End_Date__c;
|
nameNo = 1;
|
Date taskTime = MC.Contract_End_Date__c.addMonths(-2);
|
planInfo(IPInfoList, nameNo, MC, startDate, endDate, taskTime);
|
}
|
// add 一年内点检区间不够生成一次点检计划,默认生成一个点检计划,计划区间为合同开始日-结束日 2021/10/25 fxk end
|
} else {
|
// add 一年内点检区间不够生成一次点检计划,默认生成一个点检计划,计划区间为合同开始日-结束日 2021/10/25 fxk Star
|
if(Contract_validMonth < checkMonth[CheckPlan]){
|
Date startDate = MC.Contract_Start_Date__c;
|
Date endDate = MC.Contract_End_Date__c;
|
nameNo = 1;
|
Date taskTime = endDate.addMonths(-1);
|
planInfo(IPInfoList, nameNo, MC, startDate, endDate, taskTime);
|
}else{
|
// add 一年内点检区间不够生成一次点检计划,默认生成一个点检计划,计划区间为合同开始日-结束日 2021/10/25 fxk end
|
num = Integer.valueOf((Contract_validMonth - (i - 1) * 12) * CheckPlan / 12);
|
for (Integer j = 0 ; j < num ; j++) {
|
Integer keys = checkMonth[CheckPlan];
|
Date startDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + (keys * j));
|
Date endDate = MC.Contract_Start_Date__c.addMonths((i - 1) * 12 + (keys + keys * j)).addDays(-1);
|
|
//防止点检计划结束日大于合同结束日
|
if (endDate > MC.Contract_End_Date__c ) {
|
endDate = MC.Contract_End_Date__c;
|
}
|
nameNo++;
|
//2021-09-02 mzy update start
|
//发送任务的日期改成跟着实施期限的日期和合同期限的日期走,不要是固定的那个月的1号
|
//Date taskTime = Date.newInstance(endDate.year(), endDate.month() - 1, 1);
|
Date taskTime = endDate.addMonths(-1);
|
//2021-09-02 mzy update end
|
planInfo(IPInfoList, nameNo, MC, startDate, endDate, taskTime);
|
}
|
}
|
}
|
// nameNo = 0;
|
// break;
|
}
|
}
|
}
|
}
|
System.debug('1234567887654321' + MCList);
|
if (MCList.size() > 0 ) {
|
update MCList;
|
}
|
System.debug('12345678' + IPInfoList);
|
if (IPInfoList.size() > 0) {
|
insert IPInfoList;
|
// Integer a = Integer.valueOf('asdfg12345');
|
}
|
} catch (Exception ex) {
|
return ex.getMessage();
|
}
|
return '1';
|
}
|
public static List<Inspectup_Plan__c> planInfo(List<Inspectup_Plan__c> IPInfoList, Integer nameNo, Maintenance_Contract__c MC, Date startDate, Date endDate, Date taskTime) {
|
// List<Inspectup_Plan__c> IPInfoList = new List<Inspectup_Plan__c>();
|
Inspectup_Plan__c IPInfo = new Inspectup_Plan__c();
|
IPInfo.Name = '第' + nameNo + '次计划';
|
IPInfo.Maintenance_Contract__c = MC.Id;
|
IPInfo.Planned_Start_Date__c = startDate;
|
IPInfo.Planned_End_Date__c = endDate;
|
IPInfo.Task_sending_time__c = taskTime;
|
IPInfo.Chack_Plan_NO__c = String.valueOf(nameNo);
|
//2021-09-08 mzy FSE分批点检如果有遗漏设备的提醒设置 设置点检计划的合同担当,为了发邮件时使用 start
|
IPInfo.Service_Contract_Staff__c = MC.Service_Contract_Staff__c;
|
//2021-09-08 mzy FSE分批点检如果有遗漏设备的提醒设置 设置点检计划的合同担当,为了发邮件时使用 end
|
|
IPInfoList.add(IPInfo);
|
return IPInfoList;
|
}
|
// fxk 点击上传SAP按钮自动生成点检计划 2021/7/22 End
|
}
|