付煜
2022-05-05 50c80c5b21d2ed2ce208defae08620e77a7fcc48
force-app/main/default/classes/WeeklyReportCmp.cls
@@ -258,7 +258,10 @@
    @AuraEnabled
    public static List<Agency_Hospital_Link__c> getHospitalList(String hospital_name) {
        hospital_name = '%' + hospital_name.trim() + '%'; 
        return [select Hospital_Name_readonly__c, Id, Hospital__c from Agency_Hospital_Link__c where Hospital_Name_readonly__c like :hospital_name and Agency_Campaign_Obj__c = true];
        system.debug('hospital_name+++'+hospital_name);
        List<Agency_Hospital_Link__c> ahllist = [select Hospital_Name_readonly__c, Id, Hospital__c from Agency_Hospital_Link__c where Hospital_Name_readonly__c like :hospital_name and Agency_Campaign_Obj__c = true];
        system.debug('Agency_Campaign_Obj__c+++'+ahllist);
        return ahllist;
    }
    
    @RemoteAction
@@ -370,15 +373,15 @@
    */
    @RemoteAction
    @AuraEnabled//SWAG-CBX68C fy 【委托】DAMS系统周报模块内容需求增加 start SupportNeedsc
    public static String saveAgencyReport(String Department_Cateogy, String Purpose_Type, String Agency_Report_Header,String SupportNeedsc,
    @AuraEnabled//SWAG-CBX68C fy 【委托】DAMS系统周报模块内容需求增加 start SupportNeedsc ,String SupportNeedsc
    public static String saveAgencyReport(String Department_Cateogy, String Purpose_Type,String SupportNeedsc, String Agency_Report_Header,
            String Agency_Hospital, String Person_In_Charge2, String doctor, String Submit_date,
            String Product_Category1, String Product_Category2, String Product_Category3,
            String Result, String Opportunity, String StageName, String oppAmount, String oppOCMPrice, String Close_Forecasted_Date, String Report_Date)
    {
        Agency_Report__c agency_report = makeAgencyReport(Department_Cateogy, Purpose_Type, Agency_Report_Header,
            Agency_Hospital, Person_In_Charge2, doctor, Submit_date,
            Product_Category1, Product_Category2, Product_Category3,//SWAG-CBX68C fy 【委托】DAMS系统周报模块内容需求增加 start SupportNeedsc
            Product_Category1, Product_Category2, Product_Category3,//SWAG-CBX68C fy 【委托】DAMS系统周报模块内容需求增加 start SupportNeedsc   ,SupportNeedsc
            Result, Opportunity, StageName, oppAmount, oppOCMPrice, Close_Forecasted_Date, Report_Date,SupportNeedsc);
        agency_report = LightningUtil.insertAgencyReport(agency_report);
@@ -386,7 +389,7 @@
    }
    public static Agency_Report__c makeAgencyReport(String Department_Cateogy, String Purpose_Type, String Agency_Report_Header,
            String Agency_Hospital, String Person_In_Charge2, String doctor, String Submit_date,
            String Product_Category1, String Product_Category2, String Product_Category3,//SWAG-CBX68C fy 【委托】DAMS系统周报模块内容需求增加 start SupportNeeds__c
            String Product_Category1, String Product_Category2, String Product_Category3,//SWAG-CBX68C fy 【委托】DAMS系统周报模块内容需求增加 start SupportNeeds__c   ,String SupportNeedsc
            String Result, String Opportunity, String StageName, String oppAmount, String oppOCMPrice, String Close_Forecasted_Date, String Report_Date,String SupportNeedsc)
    {
        Agency_Report__c agency_report = new Agency_Report__c();
@@ -455,15 +458,15 @@
    @RemoteAction
    @AuraEnabled
    public static String editAgencyReport(String Agency_Report_Id, String Department_Cateogy, String Purpose_Type, String Agency_Report_Header,
    public static String editAgencyReport(String Agency_Report_Id, String Department_Cateogy, String Purpose_Type,String SupportNeedsc, String Agency_Report_Header,
                                        String Agency_Hospital, String Person_In_Charge2, String doctor, String Submit_date,
                                        String Product_Category1, String Product_Category2, String Product_Category3, //SWAG-CBX68C fy 【委托】DAMS系统周报模块内容需求增加 start SupportNeeds__c
                                        String Result, String Opportunity, String StageName, String oppAmount, String oppOCMPrice, String Close_Forecasted_Date, String Report_Date,String SupportNeedsc)
                                        String Product_Category1, String Product_Category2, String Product_Category3, //SWAG-CBX68C fy 【委托】DAMS系统周报模块内容需求增加 start SupportNeeds__c  ,String SupportNeedsc
                                        String Result, String Opportunity, String StageName, String oppAmount, String oppOCMPrice, String Close_Forecasted_Date, String Report_Date)
    {
        if (String.isBlank(Agency_Report_Id)) {
            return null;
        }//SWAG-CBX68C fy 【委托】DAMS系统周报模块内容需求增加 start SupportNeeds__c
        Agency_Report__c agency_report = [select Id, Name, Department_Cateogy__c, Purpose_Type__c, Agency_Hospital__c,SupportNeeds__c,
        }//SWAG-CBX68C fy 【委托】DAMS系统周报模块内容需求增加 start SupportNeeds__c   ,SupportNeeds__c
        Agency_Report__c agency_report = [select Id, Name, Department_Cateogy__c, Purpose_Type__c,SupportNeeds__c, Agency_Hospital__c,
                                          Person_In_Charge2__c, doctor2__c, Submit_date__c, Product_Category__c, Result__c, visitor_title__c, Opportunity__c
                                          from Agency_Report__c where id=:Agency_Report_Id];
        Date week = Date.valueOf(Submit_date);
@@ -588,19 +591,85 @@
        // return [select id, Name, Agency_User__c from contact where Agency_User__c = true  and AccountId in (select AccountId from User where id=:login_user_id)];
        return [select id, Name, Agency_User__c from contact];
    }
    // fy 导入 20220424 start
    public class GeDatass {
        public String dataId;
        public String doctorDivision1;
        public String doctorDivision1Encrypt;
        public Integer isDelete;
        public String name;
        public String nameEncrypt;
        public String sfRecordId;
        public String type;
        public String typeEncrypt;
    }
    @AuraEnabled
    public static String processDataAWSId(String fileData) {
       System.debug('fileData:::'+filedata);
       String errorMag = '';
       // 创建周报
       try{
            if(fileData!=null){
                String[] fileLines = new String[]{};
                fileLines = fileData.split('\n');
                // 经销商医院名称list
                List<String> ahlNameList = new List<String>();
                //for content
                system.debug('fileLines.size()==============>'+fileLines.size());
                for (Integer i=1,j=fileLines.size();i<j;i++){
                    List<String> inputvalues = new List<String>();
                    inputvalues = fileLines[i].split(',');
                    if(inputvalues != null){
                        if(inputvalues[2] == '' || inputvalues[2] == null){
                            errorMag += 'error1 第'+i+'行数据医院不能为空';
                        }
                        ahlNameList.add(inputvalues[2]);
                    }
                }
                // 经销商医院的ocsm医院id的list
                List<String> ahlOcsmIdList = new List<String>();
                List<Agency_Hospital_Link__c> ahlList = [select id,name,Hospital__c,MaxActivityDate__c from Agency_Hospital_Link__c where name = :ahlNameList and Agency_Campaign_Obj__c = true];
                for(Agency_Hospital_Link__c ahl : ahlList){
                    ahlOcsmIdList.add(ahl.Hospital__c);
                }
                List<Agency_Contact__c> doctor2list = [select id,Name,Doctor_Division1__c,Type__c,Agency_Hospital__c,AWS_Data_Id__c,Name_Encrypted__c FROM Agency_Contact__c WHERE Hospital_ID18__c= :ahlOcsmIdList order by Name];
                if(errorMag != ''){
                    return errorMag;
                }
                String doctor2listStr = JSON.serialize(doctor2list);
                return doctor2listStr;
            }
        }catch(Exception e){
             System.debug('exception'+e);
             return e.getLineNumber()+'exception:'+e;
        }
        return 'success';
    }
    // fy 导入 20220424 end
    @AuraEnabled// fy 导入 20220424  start  String sobjectName,List<String> fields,
    // public static String processData(String fileData,String Agency_ContactListjson) {
    public static String processData(String fileData,String sobjectName,List<String> fields) {
        DateTime now =System.now();
        System.debug('当前时间:::'+now);
       System.debug('fileData:::'+filedata);
       System.debug('sobjectName:::'+sobjectName);
       System.debug('fields:::'+fields);
    //    System.debug('Agency_ContactListjson::::'+Agency_ContactListjson);
       String errorMag = '';
       // 创建周报
       try{
            if(fileData!=null){ 
                // List<GeDatass> Agency_ContactList = (List<GeDatass>)JSON.deserialize(Agency_ContactListjson,List<GeDatass>.class);
                // System.debug('Agency_ContactList::::'+Agency_ContactList);
                // Map<String,String> Agency_ContactMap = new Map<String,String>();
                // for(GeDatass agconobj :Agency_ContactList){
                //     Agency_ContactMap.put(agconobj.name.replace(' ',''),agconobj.dataId);
                // }
                String[] fileLines = new String[]{};
                fileLines = fileData.split('\n');
                // 担当名称的list
@@ -622,6 +691,7 @@
                    system.debug('for2022161329');
                    List<String> inputvalues = new List<String>();
                    inputvalues = fileLines[i].split(',');
                    System.debug('inputvalues++'+inputvalues);
                    if(inputvalues != null){
                        system.debug('if2022161333');
                        if(inputvalues[0] == '' || inputvalues[0] == null){
@@ -717,7 +787,8 @@
                                errorMag += '=';
                            }
                        }
                        if(inputvalues[9] != '\r' && getResultlist(inputvalues[9])){
                        // if(inputvalues[9] != '\r' && getResultlist(inputvalues[9])){
                        if(inputvalues[9] != '' && getResultlist(inputvalues[9])){
                            // return 'error3 第'+i+'行数据结果选项列表的值'+inputvalues[9]+'不存在';
                            errorMag += 'error3 第'+i+'行数据结果选项列表的值'+inputvalues[9]+'不存在';
                            errorMag += '=';
@@ -732,6 +803,7 @@
                        system.debug('inputvalues[7]=================>'+inputvalues[7]);
                        system.debug('inputvalues[8]=================>'+inputvalues[8]);
                        system.debug('inputvalues[9]=================>'+inputvalues[9]);
                        // system.debug('inputvalues[10]=================>'+inputvalues[10]);
                        nameList.add(inputvalues[0]);
@@ -805,9 +877,14 @@
                // for(ProductTypes__c protype : proTypeList){
                //     protypeMap.put(protype.Name, protype.Id);
                // }
                List<Agency_Contact__c> doctor2list = [select id,Name,Doctor_Division1__c,Type__c,Agency_Hospital__c FROM Agency_Contact__c WHERE Hospital_ID18__c= :ahlOcsmIdList order by Name];
                //fy 20220424 start AWS_Data_Id__c
                List<Agency_Contact__c> doctor2list = [select id,Name,Doctor_Division1__c,Type__c,Agency_Hospital__c,AWS_Data_Id__c,Name_Encrypted__c FROM Agency_Contact__c WHERE Hospital_ID18__c= :ahlOcsmIdList order by Name];
                for(Agency_Contact__c ac : doctor2list){
                    doctor2Map.put(ac.Name.replace(' ',''), ac.Id);
                    //fy 20220424 start
                    // doctor2Map.put(ac.AWS_Data_Id__c, ac.Id);
                    // doctor2Map.put(ac.Name.replace(' ',''), ac.Id);
                    doctor2Map.put(ac.Name_Encrypted__c, ac.Id);
                    //fy 20220424 end
                }
                
@@ -920,9 +997,15 @@
                        // errorMag += 'error2 第'+hang+'行数据科室'+lineList[3]+'不存在';
                        // errorMag += '=';
                    }
                    if(doctor2Map.containsKey(lineList[4].replace(' ',''))){
                        agencyReport.doctor2__c = doctor2Map.get(lineList[4].replace(' ','')); // 拜访人
                    //fy 20220424 start
                    // if(doctor2Map.containsKey(lineList[4].replace(' ',''))){
                    if(doctor2Map.containsKey(lineList[4])){
                    // if(Agency_ContactMap.containsKey(lineList[4].replace(' ',''))){
                    //     if(doctor2Map.containsKey(Agency_ContactMap.get(lineList[4].replace(' ','')))){
                            // agencyReport.doctor2__c = doctor2Map.get(lineList[4].replace(' ','')); // 拜访人
                            agencyReport.doctor2__c = doctor2Map.get(lineList[4]); // 拜访人
                            // agencyReport.doctor2__c = doctor2Map.get(Agency_ContactMap.get(lineList[4].replace(' ',''))); // 拜访人
                        // }
                    }else{
                        if(lineList[4] != '' && lineList[4] != null){
                            // return 'error2 第'+hang+'行数据拜访人'+lineList[4]+'不存在';
@@ -986,6 +1069,11 @@
                    //     agencyReport.Product_Category3__c = protypeMap.get(lineList[7]);// 产品区分3
                    // }
                    agencyReport.Result__c = lineList[9];
                    if(lineList.size()==11){
                        if(lineList[10] != null && lineList[10] != ''){
                            agencyReport.SupportNeeds__c = lineList[10];
                        }
                    }
                    String headerStr = createHeader(week,s_agency);
                    if(agency_report_headerMap.containsKey(headerStr)){
                        agencyReport.Agency_Report_Header__c = agency_report_headerMap.get(headerStr).Id; // 周报一览
@@ -1025,7 +1113,7 @@
            return 'success';  
        }catch(Exception e){
             System.debug('exception'+e);
             return 'exception'+e;
             return e.getLineNumber()+'exception:'+e;
        }
        return 'success';
    }