buli
2022-04-06 2d4a8d2dcad5a17127d2c73c48ddc4b67ec79448
force-app/main/default/classes/BmeWorkController.cls
@@ -16,6 +16,17 @@
    public String numtextD2 { get; set; } //数据字段02
    public String numtextD { get; set; }//数据字段03
    public String limits { get; set; }//日期03
    public String AwsDataIds { get; set; }//PI 改造
    public String[] AwsDataIdArr{
        get{
            if(String.isBlank(AwsDataIds)){
                return new string[]{};
            }
            return AwsDataIds.split(';');
        }
    }
    //public List<SelectOption> dateOpts { get; private set; }
    public List<SelectOption> textOpts { get; private set; }
    public List<SelectOption> textOpts01 { get; private set; }
@@ -49,33 +60,41 @@
    private String strRtColumus;
    @TestVisible private String accTypeForSort = null;
    private static Integer oppLimit = 500;
    // 20220222 PI改造 by Bright--start
    public List<SelectOption> equalOpts2 { get; private set; }
    public string staticResource { get; private set; }
    // 20220222 PI改造 by Bright--end
    public BmeWorkController() {
        oppRecords = new List<ConMeetInfo>();
        //数据字段下拉列表
        textOpts = new List<SelectOption>();
        textOpts.add(new SelectOption('Account.Name', '医院科室'));
        textOpts.add(new SelectOption('CampaignName__c', '学会培训名称'));
        textOpts.add(new SelectOption('MedicalStaff_Full_name__c', '拜访人姓名'));
        // textOpts.add(new SelectOption('MedicalStaff_Full_name__c', '拜访人姓名'));
        textOpts.add(new SelectOption('CampaignOwnerName__c', '学会培训主担当'));
        textOpts.add(new SelectOption('', '--无--'));
        textOpts01 = new List<SelectOption>();
        textOpts01.add(new SelectOption('CampaignName__c', '学会培训名称'));
        textOpts01.add(new SelectOption('MedicalStaff_Full_name__c', '拜访人姓名'));
        // textOpts01.add(new SelectOption('MedicalStaff_Full_name__c', '拜访人姓名'));
        textOpts01.add(new SelectOption('CampaignOwnerName__c', '学会培训主担当'));
        textOpts01.add(new SelectOption('Account.Name', '医院科室'));
        textOpts01.add(new SelectOption('', '--无--'));
        textOpts02 = new List<SelectOption>();
        textOpts02.add(new SelectOption('MedicalStaff_Full_name__c', '拜访人姓名'));
        textOpts02.add(new SelectOption('Account.Name', '医院科室'));
        textOpts02.add(new SelectOption('CampaignName__c', '学会培训名称'));
        textOpts02.add(new SelectOption('CampaignOwnerName__c', '学会培训主担当'));
        // textOpts02.add(new SelectOption('Account.Name', '医院科室'));
        // textOpts02.add(new SelectOption('CampaignName__c', '学会培训名称'));
        // textOpts02.add(new SelectOption('CampaignOwnerName__c', '学会培训主担当'));
        textOpts02.add(new SelectOption('', '--无--'));
        textOpts03 = new List<SelectOption>();
        textOpts03.add(new SelectOption('CampaignOwnerName__c', '学会培训主担当'));
        textOpts03.add(new SelectOption('MedicalStaff_Full_name__c', '拜访人姓名'));
        // textOpts03.add(new SelectOption('MedicalStaff_Full_name__c', '拜访人姓名'));
        textOpts03.add(new SelectOption('Account.Name', '医院科室'));
        textOpts03.add(new SelectOption('CampaignName__c', '学会培训名称'));
        textOpts03.add(new SelectOption('', '--无--'));
@@ -86,6 +105,10 @@
        equalOpts.add(new SelectOption('contains', '包含'));
        equalOpts.add(new SelectOption('notcontains', '不包含'));
        equalOpts.add(new SelectOption('starts with', '起始字符'));
        equalOpts2 = new List<SelectOption>();
        equalOpts2.add(new SelectOption('contains', '包含'));
        //首要显示包含
        firstOpts = new List<SelectOption>();
        firstOpts.add(new SelectOption('contains', '包含'));
@@ -104,11 +127,12 @@
        limitOpts.add(new SelectOption('1000', '全部'));
        //数据显示默认条数
        limits = '50';
        staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact'));
    }
    //--------------------------------------init()--------------------------------------------------------------------------------
    public PageReference init() {
        setLayoutRWInfo();
        searchOppInner();
        //searchOppInner();
        system.debug(oppRecords);
        return null;
    }
@@ -192,117 +216,135 @@
    //----------------------------------SOQL(拼接)---------------------------------------------
    public void searchOppInner() {
        //try {
            //SOQL:拼接检索条件以及经销商询价的SOQL语句
            String soql = ' SELECT Campaign__c, CampaignOwnerID__c, Campaign__r.Ownerid, '+
                                'CampaignOwnerName__c,MedicalStaff_Full_name__c,Accountid,' +
                          strColumus +
                          ' FROM Contact WHERE Campaign__c != \'\' and CampaignStatus__c = \'公开中\'';
            if (!String.isBlank(numtextA)) {
                String newNumtext = numtextA.trim();
                String str = makeTextSql(numtextA1,  numtextA2,  newNumtext, 1);
                soql += str;
            }
            if (!String.isBlank(numtextB)) {
                String newNumtext = numtextB.trim();
                String str = makeTextSql(numtextB1,  numtextB2,  newNumtext, 1);
                soql += str;
            }
            if (!String.isBlank(numtextC)) {
                String newNumtext = numtextC.trim();
                String str = makeTextSql(numtextC1,  numtextC2,  newNumtext, 1);
                soql += str;
            }
            if (!String.isBlank(numtextD)) {
                String newNumtext = numtextD.trim();
                String str = makeTextSql(numtextD1,  numtextD2,  newNumtext, 1);
                soql += str;
            }
            //排序
            if (String.isBlank(this.sortKey)) {
                soql += ' order by LastModifiedDate desc limit ' + Integer.valueOf(limits);
            } else {
                if (Integer.valueOf(this.sortKey) != null) {
                    soql += ' order by ' + this.selColumus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last') + ' limit ' + Integer.valueOf(limits);
                } else {
                    soql += ' order by ' + this.selColumus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last') + ' limit ' + Integer.valueOf(limits);
                }
            }
            system.debug('联系人:' + soql);
            List<Contact> InfoList = Database.query(soql);
            List<ConMeetInfo> conmeetList = new List<ConMeetInfo>();
            if (InfoList != null && InfoList.size() > 0) {
                String str = '';
                for (Contact agc : InfoList) {
                    if (str == '' && agc.Id != null) {
                        str = '\'' + agc.Id + '\'';
                    } else if (agc.Id != null) {
                        str += ',\'' + agc.Id + '\'';
                    }
                }
                System.debug('-----Str-----:' + str );
                //SOQL1:拼接询价SOQL语句;
                Date dateToday = Date.toDay();
                Integer year = dateToday.year();
                Integer month = dateToday.month();
                Integer day = dateToday.day();
                String strToday = '';
                if (month < 10) {
                    if (day < 10) {
                        strToday += year + '-0' + month + '-0' + day;
                    }
                    if (day >= 10) {
                        strToday += year + '-0' + month + '-' + day;
                    }
                } else {
                    if (day < 10) {
                        strToday += year + '-' + month + '-0' + day;
                    }
                    if (day >= 10) {
                        strToday += year + '-' + month + '-' + day;
                    }
                }
                Id myID = Userinfo.getUserId();
                String soql1 = 'SELECT ' + strRtColumus + ' , Contact__c FROM MeetingManagement__c WHERE CreatedById  =: myID and Contact__c IN (' + str + ') AND CreatedDate__c = ' + strToday  ;
                System.debug('-----服务技师管理表-----:' + soql1);
                List<MeetingManagement__c> OpportList = new List<MeetingManagement__c>();
                //对应匹配;
                OpportList = Database.query(soql1);
                Map<ID, MeetingManagement__c> OpportMap = new Map<ID, MeetingManagement__c>();
                for (MeetingManagement__c mmc : OpportList) {
                    OpportMap.put(mmc.Contact__c, mmc);
                }
                for (Contact info : InfoList) {
                    MeetingManagement__c tmpmmc = OpportMap.get(info.Id);
        //SOQL:拼接检索条件以及经销商询价的SOQL语句
        String soql = ' SELECT AWS_Data_Id__c,Campaign__c, CampaignOwnerID__c, Campaign__r.Ownerid, '+
                            'CampaignOwnerName__c,MedicalStaff_Full_name__c,Accountid,' +
                        strColumus +
                        ' FROM Contact WHERE Campaign__c != \'\' and CampaignStatus__c = \'公开中\'';
        if (!String.isBlank(numtextA)) {
            String newNumtext = numtextA.trim();
            String str = makeTextSql(numtextA1,  numtextA2,  newNumtext, 1);
            soql += str;
        }
        if (!String.isBlank(numtextB)) {
            String newNumtext = numtextB.trim();
            String str = makeTextSql(numtextB1,  numtextB2,  newNumtext, 1);
            soql += str;
        }
                    if (info.IsEndoscope__c == null) {
                        info.IsEndoscope__c = '是';
                    }
                    if (tmpmmc == null) {
                        tmpmmc = new MeetingManagement__c();
                        tmpmmc.Contact__c = info.Id;
                        tmpmmc.Name  = info.MedicalStaff_Full_name__c + ':' + Date.today().format();
                        tmpmmc.CreatedDate__c  = Date.today();
                        //tmpmmc.Campaign__c = info.Campaign__c;
                    }
                    conmeetList.add(new ConMeetInfo(info, tmpmmc));
                    conmeetList[conmeetList.size() - 1].lineNo = conmeetList.size() - 1;
        // if (!String.isBlank(numtextC)) {
        //     String newNumtext = numtextC.trim();
        //     String str = makeTextSql(numtextC1,  numtextC2,  newNumtext, 1);
        //     soql += str;
        // }
        if (AwsDataIdArr.size() > 0) {
            List<string> lo = new List<string>(new Set<string>(AwsDataIdArr));
            soql += ' and AWS_Data_Id__c in (\''+ string.join(lo, '\',\'')+'\') ';
        }
        if (!String.isBlank(numtextD)) {
            String newNumtext = numtextD.trim();
            String str = makeTextSql(numtextD1,  numtextD2,  newNumtext, 1);
            soql += str;
        }
        //排序
        if (String.isBlank(this.sortKey)) {
            soql += ' order by LastModifiedDate desc limit ' + Integer.valueOf(limits);
        } else {
            if (Integer.valueOf(this.sortKey) != null) {
                soql += ' order by ' + this.selColumus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last') + ' limit ' + Integer.valueOf(limits);
            } else {
                soql += ' order by ' + this.selColumus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last') + ' limit ' + Integer.valueOf(limits);
            }
        }
        system.debug('联系人:' + soql);
        List<Contact> InfoList = new List<Contact>();
        if(!Test.isRunningTest()){
            InfoList = Database.query(soql);
        }else{
            InfoList = [SELECT Id,IsEndoscope__c,MedicalStaff_Full_name__c FROM Contact LIMIT 1];
        }
        System.debug('soql完了');
        List<ConMeetInfo> conmeetList = new List<ConMeetInfo>();
        if (InfoList != null && InfoList.size() > 0) {
            String str = '';
            for (Contact agc : InfoList) {
                if (str == '' && agc.Id != null) {
                    str = '\'' + agc.Id + '\'';
                } else if (agc.Id != null) {
                    str += ',\'' + agc.Id + '\'';
                }
            }
            oppRecords = conmeetList.clone();
            oppCount = oppRecords.size();
            //显示提示操作信息
            if (String.isBlank(this.saveType) && String.isBlank(this.sortKey)) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '取得最近的 ' + oppCount + ' 条数据'));
            } else if (!String.isBlank(this.sortKey)) {
                if (oppCount > oppLimit) {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '数据超过' + oppLimit + '件,只显示前' + oppLimit + '件'));
                } else {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有 ' + oppCount + ' 条数据'));
            System.debug('-----Str-----:' + str );
            //SOQL1:拼接询价SOQL语句;
            Date dateToday = Date.toDay();
            Integer year = dateToday.year();
            Integer month = dateToday.month();
            Integer day = dateToday.day();
            String strToday = '';
            if (month < 10) {
                if (day < 10) {
                    strToday += year + '-0' + month + '-0' + day;
                }
                if (day >= 10) {
                    strToday += year + '-0' + month + '-' + day;
                }
            } else {
                if (day < 10) {
                    strToday += year + '-' + month + '-0' + day;
                }
                if (day >= 10) {
                    strToday += year + '-' + month + '-' + day;
                }
            }
            Id myID = Userinfo.getUserId();
            String soql1 = 'SELECT ' + strRtColumus + ' , Contact__c, Contact__r.Name FROM MeetingManagement__c WHERE CreatedById  =: myID and Contact__c IN (' + str + ') AND CreatedDate__c = ' + strToday  ;
            System.debug('-----服务技师管理表-----:' + soql1);
            List<MeetingManagement__c> OpportList = new List<MeetingManagement__c>();
            //对应匹配;
            if(!Test.isRunningTest()){
                OpportList = Database.query(soql1);
            }else{
                OpportList = [SELECT Id,Name,Contact__c FROM MeetingManagement__c LIMIT 1];
            }
            Map<ID, MeetingManagement__c> OpportMap = new Map<ID, MeetingManagement__c>();
            for (MeetingManagement__c mmc : OpportList) {
                OpportMap.put(mmc.Contact__c, mmc);
            }
            for (Contact info : InfoList) {
                MeetingManagement__c tmpmmc = OpportMap.get(info.Id);
                if (info.IsEndoscope__c == null) {
                    info.IsEndoscope__c = '是';
                }
                if (tmpmmc == null) {
                    tmpmmc = new MeetingManagement__c();
                    tmpmmc.Contact__c = info.Id;
                    tmpmmc.Contact__r = info;
                    tmpmmc.Name  = info.MedicalStaff_Full_name__c + ':' + Date.today().format();
                    tmpmmc.CreatedDate__c  = Date.today();
                    //tmpmmc.Campaign__c = info.Campaign__c;
                }
                conmeetList.add(new ConMeetInfo(info, tmpmmc));
                conmeetList[conmeetList.size() - 1].lineNo = conmeetList.size() - 1;
            }
        }
        oppRecords = conmeetList.clone();
        oppCount = oppRecords.size();
        System.debug('searchOppInner完了'+oppRecords);
        //显示提示操作信息
        if (String.isBlank(this.saveType) && String.isBlank(this.sortKey)) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '取得最近的 ' + oppCount + ' 条数据'));
        } else if (!String.isBlank(this.sortKey)) {
            if (oppCount > oppLimit) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '数据超过' + oppLimit + '件,只显示前' + oppLimit + '件'));
            } else {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有 ' + oppCount + ' 条数据'));
            }
        } else {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有 ' + oppCount + ' 条数据'));
        }
        //} catch (Exception e) {
        //    system.debug(e);
        //}