buli
2022-05-13 2f4492ee18f90274582fcc2bb06f5e9bf64136e8
force-app/main/default/classes/SWOController.cls
@@ -17,7 +17,7 @@
   public List<RepairPart__c> rpList {get; set;}
   public List<FileAddress__c> attachmentList {get; set;}
   public List<Attachment> attachmentList {get; set;}
   public List<diagnosisInfo> diagnosisList {get; set;} 
@@ -32,32 +32,21 @@
   public RepairPart__c repairPart{get;set;}
   private String SwoStatus;
    public String staticResource { get; private set; }// 20220313 PI改造 by Chen Yanan
    public String contactstaticResource { get; private set; }// 20220313 PI改造 by Chen Yanan
    public String contactAWSDataId { get; private set; }// 20220313 PI改造 by Chen Yanan
   public String contactName { get; private set; }// 20220422 PI改造 by zhj
   public String swoawsDataId{set;get;}// 20220313 PI改造 by Chen Yanan
    public Boolean isNew { get; set; }// 20220313 PI改造 by Chen Yanan
   public String frontCaseId { get; set; }// 20220422 PI改造 by zhj
   public String frontSwoId { get; set; }// 20220424 PI改造 by zhj
   //ASSIGNEDTO__c
   public SWOController() {
      
   }
   public SWOController(ApexPages.StandardController stdController) {
      isNew = true;
      swoid = System.currentPageReference().getParameters().get('id');
      caseId = System.currentPageReference().getParameters().get('caseId');
      accId = System.currentPageReference().getParameters().get('accId');
      conId = System.currentPageReference().getParameters().get('conId');
      type = System.currentPageReference().getParameters().get('type');
        staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('SWO__c'));// 20220313 PI改造 by Chen Yanan
        contactstaticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact'));// 20220313 PI改造 by Chen Yanan
      System.debug(caseId);
   }
   public void init() {
      lineCount = 0;
      //获取初始URL
      baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
@@ -77,16 +66,12 @@
      User_FaultInfo__c ca = new User_FaultInfo__c();
      List<SWO__c> temp = new List<SWO__c>();
      if (caseId != null) {
         // ca = [select id, NUMBER__c,COMPANY__c,CONTACT__c,SUBJECT__c from User_FaultInfo__c where id = : caseId];
         ca = [select id, NUMBER__c,COMPANY__c,CONTACT__c,SUBJECT__c, CONTACT__r.AWS_Data_Id__c, CONTACT__r.Name, CONTACT__r.Email from User_FaultInfo__c where id = : caseId];// 20220313 PI改造 by Chen Yanan
         ca = [select id, NUMBER__c,COMPANY__c,CONTACT__c,SUBJECT__c from User_FaultInfo__c where id = : caseId];
         temp = [select id from SWO__c where CASE_NUMBER__c = :caseId];
         contactAWSDataId = String.isNotBlank(ca.CONTACT__r.AWS_Data_Id__c)?ca.CONTACT__r.AWS_Data_Id__c:'';
         contactName = String.isNotBlank(ca.CONTACT__r.Name)?ca.CONTACT__r.Name:'';
      }
      System.debug('ca' + ca.NUMBER__c);
      System.debug('temp' + temp.size());
      if (swoid != null) {
         isNew = false;// 20220313 PI改造 by Chen Yanan
         //初始化SWO
         Schema.DescribeSobjectResult d_swo = SWO__c.sObjectType.getDescribe();
         Map<String, Schema.SObjectField> d_swo_map = d_swo.fields.getMap();
@@ -98,24 +83,19 @@
            }
            fields_odr += field;
         }
         // soql_swo += fields_odr;
         soql_swo += fields_odr + ', CONTACT__r.AWS_Data_Id__c, CONTACT__r.Name, CONTACT__r.Email ';// 20220313 PI改造 by Chen Yanan
         soql_swo += fields_odr;
         soql_swo += ' from SWO__c where Id = \'' + swoid + '\'';
         System.debug('soql_swo: ' + soql_swo);// 20220313 PI改造 by Chen Yanan
         List<SWO__c> swoList = Database.query(soql_swo);
         System.debug('swoList: ' + swoList);// 20220313 PI改造 by Chen Yanan
         if (swoList.size() > 0) {
            swo = swoList[0];
            swoawsDataId = swo.AWS_Data_Id__c;// 20220313 PI改造 by Chen Yanan
            // contactAWSDataId = String.isNotBlank(swo.CONTACT__r.AWS_Data_Id__c)?swo.CONTACT__r.AWS_Data_Id__c:'';// 20220313 PI改造 by Chen Yanan
         }
         //初始化记录SWO 原始ASSIGNED TO,保存时判断用户是否变更,如果变更给用户发送邮件
         assignedUser = swo.ASSIGNEDTO__c;
         //初始化Mail Merge
         List<String> mailIdList = new List<String>();
         List<FileAddress__c> attList = new List<FileAddress__c>();
         Map<String, List<FileAddress__c>> attMap = new Map<String, List<FileAddress__c>>();
         List<Attachment> attList = new List<Attachment>();
         Map<String, List<Attachment>> attMap = new Map<String, List<Attachment>>();
         Map<String, Mail_Merge__c> mailMap = new Map<String, Mail_Merge__c>([select id, FROM__c, ccName__c, SUBJECT__c, MESSAGE__c, DATE__c, toName__c, EMAIL_SENT__c from Mail_Merge__c where SWO__c = :swoid order by id]);
         //mailMap = [select id,FROM__c,ccName__c,SUBJECT__c,MESSAGE__c from Mail_Merge__c where SWO__c = :id order by id];
@@ -123,15 +103,15 @@
         if (mailMap != null) {
            mailIdList.addAll(mailMap.keySet());
            attList =  [select id, Name, ParentRecordId__c,FileName__c from FileAddress__c where ParentRecordId__c in :mailIdList order by ParentRecordId__c, id];
            attList =  [select id, Name, ParentId from Attachment where ParentId in :mailIdList order by ParentId, id];
            if (attList.size() > 0) {
               for (FileAddress__c att : attList) {
                  if (attMap.containsKey(att.ParentRecordId__c)) {
                     attMap.get(att.ParentRecordId__c).add(att);
               for (Attachment att : attList) {
                  if (attMap.containsKey(att.ParentId)) {
                     attMap.get(att.ParentId).add(att);
                  } else {
                     List<FileAddress__c> a = new List<FileAddress__c>();
                     List<Attachment> a = new List<Attachment>();
                     a.add(att);
                     attMap.put(att.ParentRecordId__c, a);
                     attMap.put(att.ParentId, a);
                  }
               }
            }
@@ -157,7 +137,7 @@
         rpList = [select Id, Name, Product__c, DescriptionNew__c, PART_NUMBERNew__c, INST_SERIAL__c, QUANTITY__c, DEFECT_PART_NUMBER__c, DEFECT_SERIAL_NUMBER__c, ANI_DEFECT_CATEGORY__c, HOURS__c, LOCATION__c, BILL_AT_0_VALUE__c, ECN__c, QTY_PICKED__c,
         Product__r.Description,Product__r.Product_ECCode__c,Product__r.ProductCode from RepairPart__c where SWO_ID__c = :swoid order by Id];
         //初始化附件
         attachmentList = [select Id, Name, CreatedDate,FileName__c from FileAddress__c where ParentRecordId__c = :swoid];
         attachmentList = [select Id, Name, CreatedDate, BodyLength from Attachment where ParentId = :swoid];
         //初始化diagnosis
         List<Diagnosis_Part__c> diList = new List<Diagnosis_Part__c>();
@@ -188,7 +168,6 @@
            swo.CONTACT__c = conId;
         }
         swo.SWO_STATUS__c = 'Not Started';
         System.debug('SWO: ' + swo);
      }
      SwoStatus = swo.SWO_STATUS__c;
   }
@@ -200,7 +179,7 @@
   public PageReference save() {
      System.debug('save');
      //errorMessage = '';
      System.debug('mustData() = ' + mustData());
      //当SWO Status 改变为Quotation for approval时,此时间点自动抓取填充此处;
      if(mustData() == false){
         return null;
@@ -287,16 +266,10 @@
         //    SWOSTATUS_Closed_AddAttachment();//SWOSTATUS_Closed_AddAttachment
         // }
      }
      System.debug('swo save:' + swo);      // Update By Yanan
      if (swoid == null) {
         System.debug('frontCaseId = ' + frontCaseId);
         if(frontCaseId != null){
            swo.CASE_NUMBER__c = frontCaseId;
         }
         swo.CASE_NUMBER__c = caseId;
         insert swo;
         System.debug('swo.id = ' + swo.id);
         swoid = swo.id;
         frontSwoId = swo.id;
         //ASSIGNED TO 字段变更,给变更后的用户发邮件
         /*if(swo.ASSIGNEDTO__c!=null && swo.ASSIGNEDTO__c!=assignedUser){
            assignedUser = swo.ASSIGNEDTO__c;
@@ -344,12 +317,9 @@
      // }
      // if(insertList.size() > 0 ) insert insertList;
      //zhj 2020-04-24 前端进行跳转需要进行确认事务 start
      // PageReference ref = new Pagereference('/apex/SWOPageRead?id=' + swo.Id +'&type='+type);
      // ref.setRedirect(true);
      // return ref;
      return null;
      //zhj 2020-04-24 前端进行跳转需要进行确认事务 end
      PageReference ref = new Pagereference('/apex/SWOPageRead?id=' + swo.Id +'&type='+type);
         ref.setRedirect(true);
         return ref;
   }
   /**
   *数据验证
@@ -625,16 +595,16 @@
   public class EmailInfo {
      public Mail_Merge__c mm {get; set; }
      public List<FileAddress__c> attList {get; set; }
      public List<Attachment> attList {get; set; }
      public String haveAtt {get; set;}
      public EmailInfo() {
      }
      public EmailInfo(Mail_Merge__c mm_in, List<FileAddress__c> attList_in) {
      public EmailInfo(Mail_Merge__c mm_in, List<Attachment> attList_in) {
         mm = mm_in;
         if (attList_in == null || attList_in.size() == 0) {
            haveAtt = 'No';
            attList = new List<FileAddress__c>();
            attList = new List<Attachment>();
         } else {
            attList = attList_in;
            haveAtt = 'Yes';