高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
force-app/main/default/classes/RetrospectiveWeeklyReportController.cls
@@ -11,9 +11,15 @@
    public RetrospectiveWeeklyReportController() {
    }
    public void UserDoin(){
        system.debug('222222222222222================>');
        User UserProTypec = LightningUtil.loginUserId();
        system.debug('3333333333333================>'+UserProTypec);
        this.UserProType = '';
        this.UserProType = UserProTypec.UserPro_Type__c;
        system.debug('444444444444444================>'+this.UserProType);
    }
    
    public void setalldata()
@@ -24,6 +30,7 @@
        this.AgencyReportMap = new Map<String,Agency_Report__c>();
        
        Map<String,List<Map<String,String>>> alldata = new Map<String,List<Map<String,String>>>();
        system.debug('UserInfo.getUserId()11111111111================>'+UserInfo.getUserId());
        User login_user_id = [select UserPro_Type__c, ContactId,Contact.Name from User where id =: UserInfo.getUserId()];
        // プルダウン初期値の空白
        List<Map<String,String>> tmp = new List<Map<String,String>>();
@@ -43,6 +50,7 @@
            tmp.add(om);
        }
        this.allselectlist.put('AgencyPerson__c', tmp);
        system.debug('tmp================>'+tmp);
        //经销商人员 
        List<Map<String,String>> tmp01 = new List<Map<String,String>>();
        Map<String,String> space01 = new Map<String,String>();
@@ -51,7 +59,8 @@
        space01.put('selected', 'true');
        tmp01.add(space01);
        // 经销商人员   DealerPersonnel__c
        List<Contact> agency_person_data01 = LightningUtil.selectAgencyPerson();
        List<Contact> agency_person_data01 = LightningUtil.selectAgencyPerson02();
        system.debug('agency_person_data01================>'+agency_person_data01);
        for(Contact var : agency_person_data01) {
            Map<String,String> om01 = new Map<String,String>();
            om01.put('label', var.Name);
@@ -85,6 +94,9 @@
        //产品类别
        this.allselectlist.put('ProductCcategory__c', RetrospectiveWeeklyReportController.getPicklistValues('Agency_Report__c','ProductCcategory__c'));
        //产品类别
        this.allselectlist.put('productCategories__c', RetrospectiveWeeklyReportController.getPicklistValues('Agency_Report__c','productCategories__c'));
        //其他品牌耗材
        this.allselectlist.put('warlocksNumber__c', RetrospectiveWeeklyReportController.getPicklistValues('Agency_Report__c','warlocksNumber__c'));
@@ -190,6 +202,7 @@
    @AuraEnabled
    public static RetrospectiveWeeklyReportController getalldata(){
        RetrospectiveWeeklyReportController li = new RetrospectiveWeeklyReportController();
        system.debug('1111111111111111111111================>');
        li.UserDoin();
        li.setalldata();
        return li;
@@ -205,7 +218,6 @@
    @AuraEnabled
    public static String createReportHeader(String name, String s_date, String s_agency, String head_key){
        Agency_Report_Header__c agency_report_header = makeReportHeader(name, s_date, s_agency, head_key);
        agency_report_header = LightningUtil.upsertAgencyReportHeader(agency_report_header);
        return agency_report_header.Id;
    }
@@ -228,6 +240,7 @@
    @AuraEnabled
    public static List<Agency_Hospital_Link__c> getHospitalList(String hospital_name) {
        User login_user_id = LightningUtil.loginUserId();
        hospital_name = '%' + hospital_name.trim() + '%'; 
        if(login_user_id.UserPro_Type__c == 'ENG'){
            return [select Hospital_Name_readonly__c, Id, Hospital__c from Agency_Hospital_Link__c where Hospital_Name_readonly__c like :hospital_name and AgencyHos_ENG__c = true];
@@ -252,7 +265,6 @@
    public static List<Map<String,String>> getDoctorList(String hospital_id){
        List<Map<String,String>> ret = new List<Map<String,String>>();
        Map<String,String> space = new Map<String,String>();
        boolean flag = false;
        space.put('label', '');
        space.put('value', '');
        space.put('selected', 'true');
@@ -277,14 +289,14 @@
    @RemoteAction
    @AuraEnabled
    public static String saveAgencyReport(String Department_Cateogy,Decimal ConsumptionOfConsumables, 
                                            Boolean WorkMark,Decimal warlocksNumber,String DealerPersonnel,String ProductCcategory,String OtherBrandConsumables,
                                            Boolean WorkMark,Decimal warlocksNumber,String DealerPersonnel,String ProductCcategory,String productCategories ,String OtherBrandConsumables,
                                            String ProductClassification,String WorkRecord,String EffectProgress, String Agency_Report_Header,
                                                String Agency_Hospital, String Person_In_Charge2, String doctor, String Submit_date,
                                                String UseProduct1, String UseProduct2, String UseProduct3,
                                                String StageName, String oppAmount, String oppOCMPrice, String Close_Forecasted_Date, String Report_Date)
    {
        Agency_Report__c agency_report = makeAgencyReport(Department_Cateogy,ConsumptionOfConsumables,
        WorkMark,warlocksNumber,DealerPersonnel,ProductCcategory,OtherBrandConsumables,ProductClassification, WorkRecord,
        WorkMark,warlocksNumber,DealerPersonnel,ProductCcategory,productCategories,OtherBrandConsumables,ProductClassification, WorkRecord,
        EffectProgress,Agency_Report_Header,
            Agency_Hospital, Person_In_Charge2, doctor, Submit_date,
            UseProduct1, UseProduct2, UseProduct3,
@@ -294,7 +306,7 @@
        return agency_report.Id;
    }
    public static Agency_Report__c makeAgencyReport(String Department_Cateogy,Decimal ConsumptionOfConsumables, 
    boolean WorkMark,Decimal warlocksNumber, String DealerPersonnel,String ProductCcategory,String OtherBrandConsumables,
    boolean WorkMark,Decimal warlocksNumber, String DealerPersonnel,String ProductCcategory,String productCategories,String OtherBrandConsumables,
    String ProductClassification, String WorkRecord, String EffectProgress,String Agency_Report_Header,
            String Agency_Hospital, String Person_In_Charge2, String doctor, String Submit_date,
            String UseProduct1, String UseProduct2, String UseProduct3,
@@ -342,8 +354,9 @@
        if (UseProduct1 != '') { agency_report.UseProduct1__c = UseProduct1; }
        if (UseProduct2 != '') { agency_report.UseProduct2__c = UseProduct2; }
        if (UseProduct3 != '') { agency_report.UseProduct3__c = UseProduct3; }
        if (OtherBrandConsumables != '') { agency_report.OtherBrandConsumables__c = OtherBrandConsumables; }
        if (OtherBrandConsumables != '') { agency_report.OtherBrandConsumables__c = OtherBrandConsumables; }
        if (ProductCcategory != '') { agency_report.ProductCcategory__c = ProductCcategory; }
        if (productCategories != '') { agency_report.productCategories__c = productCategories; }
        if (warlocksNumber != null) { agency_report.warlocksNumber__c = warlocksNumber; }
        if (WorkMark != false) {
            agency_report.WorkMark__c = WorkMark; 
@@ -355,7 +368,7 @@
    @AuraEnabled
    public static String editAgencyReport(String Agency_Report_Id, String Department_Cateogy,
                                        Decimal ConsumptionOfConsumables,boolean WorkMark,Decimal warlocksNumber,
                                        String DealerPersonnel,String OtherBrandConsumables,String ProductCcategory,String ProductClassification,
                                        String DealerPersonnel,String OtherBrandConsumables,String ProductCcategory,String productCategories,String ProductClassification,
                                        String EffectProgress, String WorkRecord, String Agency_Report_Header,
                                        String Agency_Hospital, String Person_In_Charge2, String doctor, String Submit_date,
                                        String UseProduct1, String UseProduct2, String UseProduct3, 
@@ -365,7 +378,7 @@
            return null;
        }
        Agency_Report__c agency_report = [select Id, Name, Department_Cateogy__c, ConsumptionOfConsumables__c, WorkRecord__c,OtherBrandConsumables__c,
                                            ProductCcategory__c, warlocksNumber__c,WorkMark__c,ProductClassification__c,DealerPersonnel__c, Agency_Report_Header__c,Agency_Hospital__c,UseProduct1__c,
                                            ProductCcategory__c, productCategories__c,warlocksNumber__c,WorkMark__c,ProductClassification__c,DealerPersonnel__c, Agency_Report_Header__c,Agency_Hospital__c,UseProduct1__c,
                                            UseProduct2__c, UseProduct3__c,  Person_In_Charge2__c,doctor2__c,Submit_date__c,Report_Date__c
                                            from Agency_Report__c where id=:Agency_Report_Id];
        Date week = Date.valueOf(Submit_date);
@@ -401,8 +414,9 @@
        if (Agency_Hospital != '') { agency_report.Agency_Hospital__c = Agency_Hospital; } else { agency_report.Agency_Hospital__c = null; }
        if (UseProduct1 != '') { agency_report.UseProduct1__c = UseProduct1; } else { agency_report.UseProduct1__c = null; }
        if (UseProduct2 != '') { agency_report.UseProduct2__c = UseProduct2; } else { agency_report.UseProduct2__c = null; }
        if (UseProduct3 != '') { agency_report.UseProduct3__c = UseProduct3; } else { agency_report.UseProduct3__c = null; }
        if (UseProduct3 != '') { agency_report.UseProduct3__c = UseProduct3; } else { agency_report.UseProduct3__c = null; }
        if (ProductCcategory != '') { agency_report.ProductCcategory__c = ProductCcategory; } else { agency_report.ProductCcategory__c = null; }
        if (productCategories != '') { agency_report.productCategories__c = productCategories; } else { agency_report.productCategories__c = null; }
        if (OtherBrandConsumables != '') { agency_report.OtherBrandConsumables__c = OtherBrandConsumables; } else { agency_report.OtherBrandConsumables__c = null; }
        if (WorkMark != false) { agency_report.WorkMark__c = WorkMark; } else { agency_report.WorkMark__c = false; }
        if (warlocksNumber != null) { agency_report.warlocksNumber__c = warlocksNumber; } else { agency_report.warlocksNumber__c = null; }
@@ -433,8 +447,6 @@
        // 週報データを取得
        Date week = Date.valueOf(date_str);
        this.reports = LightningUtil.selectAgencyReport01(week, person_str);
        system.debug('this.reports==========>'+this.reports);
    }
    
    @RemoteAction
@@ -452,9 +464,7 @@
        Date date1_date = Date.valueOf(date1);
        Date date2_date = Date.valueOf(date2);
        RetrospectiveWeeklyReportController li = new RetrospectiveWeeklyReportController();
        List<Contact> conMList = LightningUtil.selectAgencyPerson01();
        system.debug('conMList===========>'+conMList);
        return LightningUtil.selectMAgencyReport(date1_date, date2_date, conMList);
    }
@@ -466,6 +476,7 @@
    @AuraEnabled
    public static String processData(String fileData,String sobjectName,List<String> fields) {
       String errorMag = '';
       System.debug('fileData=================>'+fileData);
       // 创建周报
       try{
            if(fileData!=null){ 
@@ -486,6 +497,10 @@
                List<String> EffectProgressList = new List<String>();
                // 术士分类
                List<String> OtherBrandConsumablesList = new List<String>();
                // 其他品牌耗材使用
                List<String> ProductCcategoryList = new List<String>();
                // 其他品牌耗材使用
                List<String> productCategoriesList = new List<String>();
                // 科室Set
                // Set<String> departmentSet = new Set<String>();
                // 经销商询价名称list
@@ -532,53 +547,63 @@
                            errorMag += '=';
                        }
                        if(inputvalues[7] == '' || inputvalues[7] == null){
                            errorMag += 'error1 第'+i+'行数据客户人员不能为空';
                            errorMag += 'error1 第'+i+'行数据医院人员不能为空';
                            errorMag += '=';
                        }
                        if(inputvalues[10] == '' || inputvalues[10] == null){
                        if(inputvalues[8] == '' || inputvalues[8] == null){
                            errorMag += 'error1 第'+i+'行数据产品分类(第三分类)不能为空';
                            errorMag += '=';
                        }
                        if(inputvalues[9] == '' || inputvalues[9] == null){
                            errorMag += 'error1 第'+i+'行数据使用产品1不能为空';
                            errorMag += '=';
                        }
                        if((inputvalues[11] != '' && inputvalues[11] != null)&& inputvalues[10] == inputvalues[11]){
                        if((inputvalues[10] != '' && inputvalues[10] != null)&& inputvalues[9] == inputvalues[10]){
                            errorMag += 'error1 第'+i+'行数据使用产品1和使用产品2的值不能重复';
                            errorMag += '=';
                        }
                        if((inputvalues[12] != '' && inputvalues[12] != null)&& inputvalues[10] == inputvalues[12]){
                        if((inputvalues[11] != '' && inputvalues[11] != null)&& inputvalues[9] == inputvalues[11]){
                            errorMag += 'error1 第'+i+'行数据使用产品1和使用产品3的值不能重复';
                            errorMag += '=';
                        }
                        if((inputvalues[11] != '' && inputvalues[11] != null) && (inputvalues[12] != '' && inputvalues[12] != null) && inputvalues[11] == inputvalues[12]){
                        if((inputvalues[10] != '' && inputvalues[10] != null) && (inputvalues[11] != '' && inputvalues[11] != null) && inputvalues[10] == inputvalues[11]){
                            errorMag += 'error1 第'+i+'行数据使用产品2和使用产品3的值不能重复';
                            errorMag += '=';
                        }
                        if(inputvalues[13] == '' || inputvalues[13] == null){
                        if(inputvalues[12] == '' || inputvalues[12] == null){
                            errorMag += 'error1 第'+i+'行数据效果/进度不能为空';
                            errorMag += '=';
                        }
                        if(inputvalues[14] == '' || inputvalues[14] == null){
                        if(inputvalues[13] == '' || inputvalues[13] == null){
                            errorMag += 'error1 第'+i+'行数据科室同类耗材月使用量不能为空';
                            errorMag += '=';
                        }
                        boolean wanked = wncc(inputvalues[14]);
                        if(!wanked && inputvalues[14] == '' || inputvalues[14] == null){
                        boolean wanked = wncc(inputvalues[13]);
                        if(!wanked && inputvalues[13] == '' || inputvalues[13] == null){
                            errorMag += 'error3 第'+i+'行数据错误,请检查你的科室同类耗材月使用量!';
                            errorMag += '=';
                        }
                        //暂时注掉因为ENG的术士分类为空所以暂时注掉
                        // if(inputvalues[14] == '' || inputvalues[14] == null){
                        //     errorMag += 'error1 第'+i+'行数据其他品牌耗材使用不能为空';
                        //     errorMag += '=';
                        // }
                        if(inputvalues[15] == '' || inputvalues[15] == null){
                            errorMag += 'error1 第'+i+'行数据其他品牌耗材使用不能为空';
                            errorMag += 'error1 第'+i+'行数据已采用其他产品不能为空';
                            errorMag += '=';
                        }
                        if(inputvalues[16] == '' || inputvalues[16] == null){
                            errorMag += 'error1 第'+i+'行数据产品类别不能为空';
                            errorMag += '=';
                        }
                        //暂时注掉因为ET的其他品牌产品类别没有数据
                        // if(inputvalues[16] == '' || inputvalues[16] == null){
                        //     errorMag += 'error1 第'+i+'行数据术士使用产品对应数量不能为空';
                        //     errorMag += '=';
                        // }
                        if(inputvalues[17] == '' || inputvalues[17] == null){
                            errorMag += 'error1 第'+i+'行数据术士使用产品对应数量不能为空';
                            errorMag += 'error1 第'+i+'行数据术产品用量不能为空';
                            errorMag += '=';
                        }
                        boolean wankeds = wncc(inputvalues[17]);
                        if(!wankeds && inputvalues[17] == '' || inputvalues[17] == null){
                            errorMag += 'error3 第'+i+'行数据错误,请检查你的术士使用产品对应数量!';
                            errorMag += 'error3 第'+i+'行数据错误,请检查你的产品用量!';
                            errorMag += '=';
                        }
                        system.debug('inputvalues[1]====='+inputvalues[1]);
@@ -592,12 +617,13 @@
                        system.debug('inputvalues[9]====='+inputvalues[9]);
                        system.debug('inputvalues[10]====='+inputvalues[10]);
                        system.debug('inputvalues[11]====='+inputvalues[11]);
                        system.debug('inputvalues[7]====='+inputvalues[12]);
                        system.debug('inputvalues[8]====='+inputvalues[13]);
                        system.debug('inputvalues[9]====='+inputvalues[14]);
                        system.debug('inputvalues[10]====='+inputvalues[15]);
                        system.debug('inputvalues[11]====='+inputvalues[16]);
                        system.debug('inputvalues[11]====='+inputvalues[17]);
                        system.debug('inputvalues[12]====='+inputvalues[12]);
                        system.debug('inputvalues[13]====='+inputvalues[13]);
                        system.debug('inputvalues[14]====='+inputvalues[14]);
                        system.debug('inputvalues[15]====='+inputvalues[15]);
                        system.debug('inputvalues[16]====='+inputvalues[16]);
                        system.debug('inputvalues[17]====='+inputvalues[17]);
                        system.debug('inputvalues[18]====='+inputvalues[18]);
                        //担当
                        nameList.add(inputvalues[1]);
                        //报告日
@@ -605,20 +631,24 @@
                        //经销商医院
                        ahlNameList.add(inputvalues[3]);
                        //使用产品1
                        Product2NameList.add(inputvalues[9]);
                        //使用产品2
                        Product2NameList.add(inputvalues[10]);
                        //使用产品3
                        Product2NameList.add(inputvalues[11]);
                        EffectProgressList.add(inputvalues[14]);
                        OtherBrandConsumablesList.add(inputvalues[12]);
                        //效果进度
                        EffectProgressList.add(inputvalues[12]);
                        //术士分类
                        OtherBrandConsumablesList.add(inputvalues[14]);
                        //已采用其他品牌
                        ProductCcategoryList.add(inputvalues[15]);
                        //其他品牌产品类别
                        productCategoriesList.add(inputvalues[16]);
                        //科室
                        // departmentSet.add('%'+GetDepartment_Cateogy(inputvalues[4])+'%'+'-'+GetEPurposeType(inputvalues[10]));
                        //导入的数据
                        inputList.add(inputvalues);
                    }
                }
                // 担当名称匹配的map
@@ -636,12 +666,20 @@
                Map<String,EffectProgress__c> EffectProgressMap = new Map<String,EffectProgress__c>();
                // 术士分类
                Map<String,WarlockClassification__c> OtherBrandConsumablesMap = new Map<String,WarlockClassification__c>();
                // 已采用其他产品
                Map<String,ProductCcategory__c> ProductCcategorynMap = new Map<String,ProductCcategory__c>();
                 // 其他品牌产品类别
                 Map<String,productCategories__c> productCategoriesMap = new Map<String,productCategories__c>();
                // 使用产品id的List
                List<String> UseProductIdList = new List<String>();
                 // 效果进度id的List
                 List<String> EffectProgressIdList = new List<String>();
                  // 术士分类id的List
                List<String> OtherBrandConsumablesIdList = new List<String>();
                  // 已采用其他品牌id的List
                  List<String> ProductCcategorynIdList = new List<String>();
                  // 其他品牌产品类别id的List   productCategoriesMap
                  List<String> productCategoriesIdList = new List<String>();
                // 产品区分的map
                Map<String,String> protypeMap = new Map<String,String>();
                // 获取每周第一天的map
@@ -654,15 +692,14 @@
                Map<String,String> DealerPersonnelMap = new Map<String,String>();
                // 经销商询价的map
                Map<String,Agency_Opportunity__c> aoMap = new Map<String,Agency_Opportunity__c>();
                // 科室和产品区分关系map
                // Map<String,List<Map<String,String>>> impProMap = new  Map<String,List<Map<String,String>>>();
                // impProMap = getImplProductList(departmentSet);
                List<Contact> conList = LightningUtil.selectAgencyPerson01();      
                List<OlympusCalendar__c> olympusDateList = [select Id,Date__c,FirstDayOfWeek__c,DayOfTheWeek__c from OlympusCalendar__c where Date__c= :dateList ];
                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];
                List<Product2> pr2List = [select id,name from Product2 where name = :Product2NameList];
                List<EffectProgress__c> epList = [select id,name from EffectProgress__c where name = :EffectProgressList];
                List<WarlockClassification__c> ocList = [select id,name from WarlockClassification__c where name = :OtherBrandConsumablesList];
                List<Product2> pr2List = [select id,name from Product2 where name in:Product2NameList];
                List<EffectProgress__c> epList = [select id,name from EffectProgress__c where name in :EffectProgressList];
                List<WarlockClassification__c> ocList = [select id,name from WarlockClassification__c where name in :OtherBrandConsumablesList];
                List<ProductCcategory__c> PCList = [select id,name from ProductCcategory__c where name in :ProductCcategoryList];
                List<productCategories__c> PctList = [select id,name from productCategories__c where name in :productCategoriesList];
                
                for(OlympusCalendar__c olym : olympusDateList){
                    if(olym.DayOfTheWeek__c == 'Sun'){
@@ -694,16 +731,24 @@
                    EffectProgressMap.put(ep.Name, ep);
                    EffectProgressIdList.add(ep.Id);
                }
                for(WarlockClassification__c oc : ocList){
                for(WarlockClassification__c oc : ocList){
                    OtherBrandConsumablesMap.put(oc.Name, oc);
                    OtherBrandConsumablesIdList.add(oc.Id);
                }
                for(ProductCcategory__c pc : PCList){
                    ProductCcategorynMap.put(pc.Name, pc);
                    ProductCcategorynIdList.add(pc.Id);
                }
                for(productCategories__c pct : PctList){
                    productCategoriesMap.put(pct.Name, pct);
                    productCategoriesIdList.add(pct.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];
                for(Agency_Contact__c ac : doctor2list){
                    doctor2Map.put(ac.Name.replace(' ',''), ac.Id);
                }
                //经销商人员  DealerPersonnel
                List<contact> conListLighrningUtil = LightningUtil.selectAgencyPerson();
                List<contact> conListLighrningUtil = LightningUtil.selectAgencyPerson02();
                for(contact de : conListLighrningUtil){
                    DealerPersonnelMap.put(de.Name.replace(' ',''), de.Id);
                }
@@ -762,37 +807,34 @@
                    }
                    Agency_Report__c agencyReport = new Agency_Report__c();
                    if(week == null && lineList[2] != '' && lineList[2] != null){
                        // return 'error2 第'+hang+'行数据报告日'+lineList[1]+'填写有误';
                        errorMag += 'error2 第'+hang+'行数据报告日'+lineList[2]+'填写有误';
                        errorMag += '=';
                    }
                    agencyReport.Submit_date__c = week;   // 提出周
                    agencyReport.Submit_date__c = week;
                    if((s_agency == null || s_agency == '')&& lineList[1] != '' && lineList[1] != null){
                        errorMag += 'error2 第'+hang+'行数据担当'+lineList[1]+'不存在';
                        errorMag += '=';
                    }
                    agencyReport.Person_In_Charge2__c = s_agency;  // 担当
                    agencyReport.Person_In_Charge2__c = s_agency;
                    if(lineList[2] != null && lineList[2] != ''){
                        agencyReport.Report_Date__c = Date.valueOf(lineList[2].replace('/','-')); // 活动日
                        agencyReport.Report_Date__c = Date.valueOf(lineList[2].replace('/','-'));
                    }
                    if(ahlMap.containsKey(lineList[3])){
                        agencyReport.Agency_Hospital__c = ahlMap.get(lineList[3]).Id; //经销商医院    UseProduct1__c
                        // 更新经销商医院的最新周
                        agencyReport.Agency_Hospital__c = ahlMap.get(lineList[3]).Id;
                        ahlMap.get(lineList[3]).MaxActivityDate__c = week;
                    }else{
                        if(lineList[3] != '' && lineList[3] != null){
                            // return 'error2 第'+hang+'行数据经销商医院'+lineList[2]+'不存在';
                            errorMag += 'error2 第'+hang+'行数据经销商医院'+lineList[3]+'不存在';
                            errorMag += '=';
                        }
                    }
                    String departmentE = GetDepartment_Cateogy(lineList[4]);
                    if(departmentE != 'no'){
                        agencyReport.Department_Cateogy__c = departmentE;  // 科室
                        agencyReport.Department_Cateogy__c = departmentE;
                    }else{
                    }
                    if(DealerPersonnelMap.containsKey(lineList[5].replace(' ',''))){ 
                        agencyReport.DealerPersonnel__c = DealerPersonnelMap.get(lineList[5].replace(' ','')); // 经销商人员   DealerPersonnelMap
                        agencyReport.DealerPersonnel__c = DealerPersonnelMap.get(lineList[5].replace(' ',''));
                    }else{
                        if(lineList[5] != '' && lineList[5] != null){
                            errorMag += 'error2 第'+hang+'行数据经销商人员'+lineList[5]+'不存在';
@@ -800,10 +842,10 @@
                        }
                    }
                    if(GetPurposeType(lineList[6])){
                        agencyReport.WorkRecord__c = lineList[6]; // 活动区分
                        agencyReport.WorkRecord__c = lineList[6];
                    }
                    if(doctor2Map.containsKey(lineList[7].replace(' ',''))){ 
                        agencyReport.doctor2__c = doctor2Map.get(lineList[7].replace(' ','')); // 拜访人
                        agencyReport.doctor2__c = doctor2Map.get(lineList[7].replace(' ',''));
                    }else{
                        if(lineList[7] != '' && lineList[7] != null){
                            errorMag += 'error2 第'+hang+'行数据客户人员'+lineList[7]+'不存在';
@@ -811,10 +853,10 @@
                        }
                    }
                    if(GetProductClassification(lineList[8])){
                        agencyReport.ProductClassification__c = lineList[8]; // 产品分类
                        agencyReport.ProductClassification__c = lineList[8];
                    }
                    if(UseProductMap.containsKey(lineList[9])){
                        agencyReport.UseProduct1__c = UseProductMap.get(lineList[9]).Id; //使用产品1
                        agencyReport.UseProduct1__c = UseProductMap.get(lineList[9]).Id;
                    }else{
                        if(lineList[9] != '' && lineList[9] != null){
                            errorMag += 'error2 第'+hang+'行数据使用产品1'+lineList[9]+'不存在';
@@ -822,7 +864,7 @@
                        }
                    }
                    if(UseProductMap.containsKey(lineList[10])){
                        agencyReport.UseProduct2__c = UseProductMap.get(lineList[10]).Id; //使用产品2      EffectProgressMap  OtherBrandConsumablesMap
                        agencyReport.UseProduct2__c = UseProductMap.get(lineList[10]).Id;
                    }else{
                        if(lineList[10] != '' && lineList[10] != null){
                            errorMag += 'error2 第'+hang+'行数据使用产品2'+lineList[10]+'不存在';
@@ -830,7 +872,7 @@
                        }
                    }
                    if(UseProductMap.containsKey(lineList[11])){
                        agencyReport.UseProduct3__c = UseProductMap.get(lineList[11]).Id; //使用产品3
                        agencyReport.UseProduct3__c = UseProductMap.get(lineList[11]).Id;
                    }else{
                        if(lineList[11] != '' && lineList[11] != null){
                            errorMag += 'error2 第'+hang+'行数据使用产品3'+lineList[11]+'不存在';
@@ -838,41 +880,42 @@
                        }
                    }
                    if(EffectProgressMap.containsKey(lineList[12])){
                        agencyReport.EffectProgress__c = EffectProgressMap.get(lineList[12]).Id; // 效果/进度
                        agencyReport.EffectProgress__c = EffectProgressMap.get(lineList[12]).Id;
                    }
                    if(lineList[13] != null){
                        agencyReport.ConsumptionOfConsumables__c = Decimal.valueOf(lineList[13]); // 科室同类耗材月使用量
                        agencyReport.ConsumptionOfConsumables__c = Decimal.valueOf(lineList[13]);
                    }
                    if(OtherBrandConsumablesMap.containsKey(lineList[14])){
                        agencyReport.EffectProgress__c = OtherBrandConsumablesMap.get(lineList[14]).Id; // 术士分类
                        agencyReport.OtherBrandConsumables__c = OtherBrandConsumablesMap.get(lineList[14]).Id;
                    }
                        // agencyReport.OtherBrandConsumables__c = lineList[14]; // 术士分类
                    if(GetProductCcategory(lineList[15])){
                        agencyReport.ProductCcategory__c = lineList[15]; // 产品类别
                    if(ProductCcategorynMap.containsKey(lineList[15])){
                        agencyReport.ProductCcategory__c = ProductCcategorynMap.get(lineList[15]).Id;
                    }
                    if(lineList[16] != null){
                        agencyReport.warlocksNumber__c = Decimal.valueOf(lineList[16]); // 术士使用产品对应数量     warlocksNumber__c    EffectProgress__c
                    if(productCategoriesMap.containsKey(lineList[16])){
                        agencyReport.productCategories__c = productCategoriesMap.get(lineList[16]).Id;
                    }
                    if(lineList[17] == 'true'){
                        agencyReport.WorkMark__c =  true;  //工作标记
                    if(lineList[17] != null){
                        agencyReport.warlocksNumber__c = Decimal.valueOf(lineList[17]);
                    }
                    if(lineList[18] == 'true'){
                        agencyReport.WorkMark__c =  true;
                    }else{
                        agencyReport.WorkMark__c =  false; 
                    }
                    String headerStr = createHeader(week,s_agency);
                    if(agency_report_headerMap.containsKey(headerStr)){
                        agencyReport.Agency_Report_Header__c = agency_report_headerMap.get(headerStr).Id; // 周报一览
                        agencyReport.Agency_Report_Header__c = agency_report_headerMap.get(headerStr).Id;
                    }
                    hang++;
                    arList.add(agencyReport);
                }
                if(errorMag != ''){
                    system.debug('errorMag==========>'+errorMag);
                    return errorMag;
                }
                // 更新经销商意愿的最新周
                if(ahlMap.values().size() > 0 ){
                    update ahlMap.values();
                }
                // 新增周报明细
@@ -882,8 +925,8 @@
            }
            return 'success';  
        }catch(Exception e){
             System.debug('exception'+e);
             return 'exception'+e;
                System.debug('exception'+e);
                return 'exception'+e;
        }
    }
@@ -935,41 +978,6 @@
        }
        return false;
    }
    // 判断产品类别是否存在
    public static boolean GetProductCcategory(String purposeType){
        Schema.DescribeFieldResult fieldResult = Agency_Report__c.ProductCcategory__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            if(pickListVal.getValue() == purposeType){
                return true;
            }
        }
        return false;
    }
    // 判断其他品牌耗材使用是否存在    OtherBrandConsumables__c
    // public static boolean GetOtherBrandConsumables(String purposeType){
    //     Schema.DescribeFieldResult fieldResult = Agency_Report__c.OtherBrandConsumables__c.getDescribe();
    //     List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    //     for( Schema.PicklistEntry pickListVal : ple){
    //         if(pickListVal.getValue() == purposeType){
    //             return true;
    //         }
    //     }
    //     return false;
    // }
    // 判断效果/进度是否存在   EffectProgress__c GetProductClassification
    // public static boolean GetEffectProgress(String purposeType){
    //     Schema.DescribeFieldResult fieldResult = Agency_Report__c.EffectProgress__c.getDescribe();
    //     List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    //     for( Schema.PicklistEntry pickListVal : ple){
    //         if(pickListVal.getValue() == purposeType){
    //             return true;
    //         }
    //     }
    //     return false;
    // }
     // 判断效果/进度是否存在    
     public static boolean GetProductClassification(String purposeType){
        Schema.DescribeFieldResult fieldResult = Agency_Report__c.ProductClassification__c.getDescribe();
@@ -1048,6 +1056,8 @@
    @RemoteAction
    @AuraEnabled
    public static List<Map<String,String>> selectPurposeTypes(String doctor_value){
        system.debug('doctor_value===============>'+doctor_value);
        List<EffectProgress__c> eftpcList;
        if(String.isNotBlank(doctor_value)){
            eftpcList = [select id, Name , WorkRecord__c from EffectProgress__c where WorkRecord__c =: doctor_value];
@@ -1063,13 +1073,13 @@
            efptcMap.put('value', efptc.Id);
            options.add(efptcMap);
        }
        system.debug('options===============>'+options);
        return options;
    }
    @RemoteAction
    @AuraEnabled
    public static List<Map<String,String>> selectProductClassificationc(String select_ProductClassification){
        List<WarlockClassification__c> WarlockClassificationList;
        system.debug('select_ProductClassification==============='+select_ProductClassification);
        if(String.isNotBlank(select_ProductClassification)){
            WarlockClassificationList = [select id, Name , ProductClassification__c from WarlockClassification__c where ProductClassification__c =: select_ProductClassification];
        }
@@ -1084,7 +1094,54 @@
            WarlockClassificationMap.put('value', WarlockClassification.Id);
            options.add(WarlockClassificationMap);
        }
        system.debug('options==============='+options);
        return options;
    }
    @RemoteAction
    @AuraEnabled
    public static List<Map<String,String>> selectProductCcategory(){
        List<ProductCcategory__c> ProductCcategoryList;
        User UserProETENG = LightningUtil.loginUserId();
        if(UserProETENG.UserPro_Type__c == 'ET'){
            ProductCcategoryList = [select id, Name , ConsumablesClassification__c from ProductCcategory__c where ConsumablesClassification__c =: 'ET'];
        }else{
            ProductCcategoryList = [select id, Name , ConsumablesClassification__c from ProductCcategory__c where ConsumablesClassification__c =: 'ENG'];
        }
        List<Map<String,String>> options = new List<Map<String,String>>();
        Map<String,String> space = new Map<String,String>();
        space.put('label', '');
        space.put('value', '');
        options.add(space);
        for(ProductCcategory__c ProductCcategory : ProductCcategoryList){
            Map<String,String> ProductCcategorynMap = new Map<String,String>();
            ProductCcategorynMap.put('label', ProductCcategory.Name);
            ProductCcategorynMap.put('value', ProductCcategory.Id);
            options.add(ProductCcategorynMap);
        }
        return options;
    }
    @RemoteAction
    @AuraEnabled
    public static List<Map<String,String>> selectProductCcategory01(String select_ProductCcategory){
        List<productCategories__c> productCategoriesList;
        User UserProETENG = LightningUtil.loginUserId();
        System.debug('UserProETENG.UserPro_Type__c=============>'+UserProETENG.UserPro_Type__c);
        if(UserProETENG.UserPro_Type__c == 'ET'){
            productCategoriesList = [select id, Name,ET_ENG_classification__c,ProductCcategory__c from productCategories__c where ProductCcategory__c =:select_ProductCcategory AND ET_ENG_classification__c =: 'ET'];
        }else{
            productCategoriesList = [select id, Name,ET_ENG_classification__c,ProductCcategory__c from productCategories__c where ProductCcategory__c =:select_ProductCcategory AND ET_ENG_classification__c =: 'ENG'];
        }
        List<Map<String,String>> options = new List<Map<String,String>>();
        Map<String,String> space = new Map<String,String>();
        space.put('label', '');
        space.put('value', '');
        options.add(space);
        for(productCategories__c productCategories : productCategoriesList){
            Map<String,String> productCategoriesMap = new Map<String,String>();
            productCategoriesMap.put('label', productCategories.Name);
            productCategoriesMap.put('value', productCategories.Id);
            options.add(productCategoriesMap);
        }
        System.debug('options=============>'+options);
        return options;
    }
}