global class updateFirstServiceContractWebService{
|
|
WebService static String updateFirstContract(String mcid ){
|
List<Maintenance_Contract__c> mcList = [select id, Effective_Status__c,Status__c,upload_to_sap_time__c from Maintenance_Contract__c where id = :mcid ];
|
if (mcList.size() == 0) {
|
return '维修合同不存在,请确认维修合同ID。';
|
}
|
Maintenance_Contract__c mc = mcList[0];
|
List<Maintenance_Contract_Asset__c> mcaList = [select id,Maintenance_Contract__r.Contract_Start_Date__c,Maintenance_Contract__r.Contract_End_Date__c,Maintenance_Contract__r.Maintenance_Contract_No__c,Asset__r.name,Asset__r.id,asset__r.First_Service_number__c,asset__r.First_Service_Start_Day__c,asset__r.First_Service_End_Day__c
|
from Maintenance_Contract_Asset__c where Maintenance_Contract__c = :mc.id];
|
List<Asset> assList = new List<Asset>();
|
if (mc.Effective_Status__c =='有效' && mc.Status__c =='契約'&&mc.upload_to_sap_time__c==null && mcaList!= null) {
|
for (Maintenance_Contract_Asset__c mca:mcaList) {
|
Asset ass = new Asset();
|
ass.id = mca.asset__r.id;
|
if (mca.asset__r.First_Service_number__c == null) {
|
ass.First_Service_number__c = mca.Maintenance_Contract__r.Maintenance_Contract_No__c;
|
}
|
if (mca.asset__r.First_Service_End_Day__c == null) {
|
ass.First_Service_End_Day__c = mca.Maintenance_Contract__r.Contract_End_Date__c;
|
}
|
if (mca.asset__r.First_Service_Start_Day__c == null) {
|
ass.First_Service_Start_Day__c = mca.Maintenance_Contract__r.Contract_Start_Date__c;
|
}
|
assList.add(ass);
|
}
|
}
|
try{
|
if (assList.size()>0) {
|
update assList;
|
}
|
}catch(Exception e){
|
return e.getMessage();
|
}
|
return '1';
|
}
|
|
|
}
|