123
chenjingwu
2024-04-23 b51b57a619d3f0075ccaa13303c99c9e849bf23a
force-app/main/default/classes/MaintenanceProductDataController.cls
@@ -49,6 +49,13 @@
    public String soql {get;set;}
    //---
    
    // chenjingwu 3+2多年保修 start
    public List<MultiYearWarranty__c> muList { get; set; }
    public Map<String,List<MultiYearWarranty__c>> muMap { get; set; }
    public Map<String,Integer> muCountMap {get; set; }
    public Map<String,List<ExMpdDetailsInfo>>  exmpdDetailsRecordsMap { get; set; }
    // chenjingwu 3+2多年保修 end
     /*****************画面表示Bean******************/
    //private List<MaintenanceProductDataDetailsInfo> mpdDerdetailsRecords = new List<MaintenanceProductDataDetailsInfo>();
    public  List<MaintenanceProductDataDetailsInfo> mpdDetailsRecordsView { get; set; }//页面的明细
@@ -68,7 +75,9 @@
    //LJPH-C6A3DF 【委托】 【重要】产品主数据中增加服务用产品分类 liuyan 20210908 Star
    public List<Maintenance_Product_Data_Details__c>  RepairInfo { 
        get {
            // 20231103 陈京武  sitbug对应 Start
            return  [select id,Service_Category6__c,Service_Category7__c FROM Maintenance_Product_Data_Details__c  where Default_Fixture_Arrival_Product__c = '' and Service_Category6__c = null and Service_Category7__c = null  LIMIT 1 ];
            // 20231103 陈京武  sitbug对应 End
        }
    }
    //LJPH-C6A3DF 【委托】 【重要】产品主数据中增加服务用产品分类 liuyan 20210908 End
@@ -83,7 +92,9 @@
    public Boolean editDelCommitBtnDisabled {get; private set;}
    public Boolean saveBtnDisabled { get; private set; }
    //public Boolean sorderBtnDisabled { get; private set; }
    // 20231103 chenjingwu  Lightning文件修改 Start
    private List<ContentDocument> attachmentinfo = new List<ContentDocument>();
    // 20231103 chenjingwu  Lightning文件修改 End
    //-----------
    private void initStandardController(){
@@ -160,6 +171,7 @@
                    // 20221020 ljh SWAG-CJ98AJ start
                    mpdDetailsRecordsView[i].mpdrdd.suitDepartment__c = mpdDetailsRecordsView[i].Prod.suitDepartment__c;
                    // 20221020 ljh SWAG-CJ98AJ end
                    mpdDetailsRecordsView[i].mpdrdd.LastbuyProductFLG__c = mpdDetailsRecordsView[i].Prod.LastbuyProductFLG__c;//kk lastbuy add 20240329 add
                }
                if(RecordTypeName.equals('GuranteeMain')){
                    Integer Entend_gurantee_period_all =  mpdDetailsRecordsView[i].Prod.Entend_gurantee_period_all__c.intValue();
@@ -311,13 +323,13 @@
        if(profileId.equals(System.Label.ProfileId_EquCenAdminPic)){
            profileName = '2B3';
        }
        if(profileId.equals('00e10000000xno4AAA')){
        if(profileId.equals(System.Label.profileId_2F3)){//niwu -00eC600000004OXIAY
            profileName = '2F3';//服务
        }
        if(profileId.equals('00e10000000xyViAAI')){
        if(profileId.equals(System.Label.ProfileId_2M5)){
            profileName = '2M5';//产品
        }
        if (profileId.equals('00e10000000xno9AAA')) {
        if (profileId.equals(System.Label.ProfileId_2F4)) { //niwu  - 00eC600000004OZIAY
            profileName = '2F4';//技术推进部
        }
        if(String.isBlank(id)&&String.isBlank(RecordTypeName)){
@@ -352,6 +364,8 @@
            fsTemp += 'YY';
            fsTempOld += 'YY';
        }*/
        System.debug('RecordTypeName>>>>>>> ' + RecordTypeName);
        System.debug('profileName>>>>>>> ' + profileName);
        if(RecordTypeName.equals('GuranteeMain')&&profileName.equals('2M5')){
            fsTemp += 'FW';
            fsTempOld += 'FW';
@@ -414,6 +428,9 @@
        }else{
            List<Maintenance_Product_Data_Details__c> mpdDetailsSelected = new List<Maintenance_Product_Data_Details__c>();
            String mpdsoql = 'select Id ,Name,GuranteeTypeP__c,ProductCode_Ext__c ,ProductsID__c,Maintenance_Product_Data__c,ProductsID__r.Name  ';
            //kk lastbuy add 20240328 start
            mpdsoql += ' ,ProductsID__r.LastbuyProductFLG__c,LastbuyProductFLG__c';
            //kk lastbuy add 20240328 end
            for (Integer i=0;i<column.size();i++) {
                mpdsoql += ',' + column[i];
            }
@@ -475,6 +492,7 @@
                }
            }
            //附件(lightning)
            // 20231103 chenjingwu  Lightning文件修改 Start
            List<ContentDocumentLink> cdlList = [SELECT ContentDocumentId
                                                   FROM ContentDocumentLink
                                                   WHERE LinkedEntityId = :id];
@@ -483,8 +501,8 @@
                fileIDs.add(docLink.ContentDocumentId);
            }
            attachmentinfo=[SELECT Title,OwnerId,ContentModifiedDate from ContentDocument WHERE id IN :fileIDs];
            // attachmentinfo =[SELECT Id, Name,OwnerId FROM Attachment WHERE  parentid =:id  ];
            // 20231103 chenjingwu  Lightning文件修改 End
            if(attachmentinfo.size()>0){
                for (Integer i = 0; i < attachmentinfo.size(); i++) {
                    attachmentRecoeds.add(new MaintenanceProductDataDetailsInfo(attachmentinfo[i]));
@@ -510,11 +528,37 @@
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,  '还没有上传附件,请上传附件!'));
                } 
            }
            //System.debug('============02:'+mpdDetailsRecords);
            //System.debug('============02:'+mpdDetailsRecords);
            if(mpdDetailsRecords.size() > 0 && RecordTypeName.equals('GuranteeMain')){
                // chenjingwu 3+2多年保修 20240417 start
                List<String> idList = new List<String>();
                for(MpdDetailsInfo mp :mpdDetailsRecords){
                    idList.add(mp.mpded.ProductsID__c);
                }
                // chenjingwu 3+2多年保修 20240417 end
                // chenjingwu 3+2多年保修 20240417 start
                exmpdDetailsRecordsMap = new Map<String,List<ExMpdDetailsInfo>>();
                muCountMap = new Map<String,Integer>();
                List<Maintenance_Product_Data_Details__c> exDetailList = [select Id,MultiYearWarranty__c,AgeLimit__c,AgeLimit_Old__c,MultiOneYearWarrantyPrice__c,MultiOneYearWarrantyPrice_Old__c,AmountWithheld__c,AmountWithheld_Old__c,ProductsID__c from Maintenance_Product_Data_Details__c where ProductsID__c in:idList and RecordTypeId = '012C50000000jefIAA'];
                if(exDetailList.size() > 0){
                    for(String id: idList){
                        List<ExMpdDetailsInfo> exList = new List<ExMpdDetailsInfo>();
                        for(Maintenance_Product_Data_Details__c mpdd: exDetailList){
                            if(id == mpdd.ProductsID__c){
                                exList.add(new ExMpdDetailsInfo(mpdd));
                            }
                        }
                        exList.add(new ExMpdDetailsInfo());
                        exmpdDetailsRecordsMap.put(id,exList);
                    }
                }
                // chenjingwu 3+2多年保修   20240417 end
            }
        }    
    }
    // 检索
    public void searchMaintenanceProductDataDetails() {
        System.debug('enter searchMaintenanceProductDataDetails');
        Map<String, String> selectedIdMap = new Map<String, String>();
        Map<String,MaintenanceProductDataDetailsInfo> midMaprecord = new Map<String,MaintenanceProductDataDetailsInfo>();
        mpdDetailsRecordsView = new List<MaintenanceProductDataDetailsInfo>();
@@ -525,7 +569,9 @@
        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,  '=====soql:'+soql));
        size =Integer.valueOf(System.Label.mpddetLimitsize);
        initStandardController();
        product2Selected = Database.query(soql);
        product2Selected = Database.query(soql);
        System.debug('product2Selected size = ' + product2Selected.size());
        System.debug('product2Selected = ' + product2Selected);
        for (Integer i = 0; i < product2Selected.size(); i++) {
            midMaprecord.put(product2Selected[i].Id, new MaintenanceProductDataDetailsInfo(product2Selected[i]));
        }
@@ -542,7 +588,29 @@
        // 显示数据条数信息
        makeMessage();
    }
    // 20231103 chenjingwu  Lightning文件修改 Start
    public void refreshFile(){
        if(String.isBlank(id)){
            return;
        }
        attachmentRecoeds = new List<MaintenanceProductDataDetailsInfo>();
        List<ContentDocumentLink> cdlList = [SELECT ContentDocumentId
                                               FROM ContentDocumentLink
                                               WHERE LinkedEntityId = :id];
        List<ID> fileIDs = new List<ID>();
        for (ContentDocumentLink docLink : cdlList) {
            fileIDs.add(docLink.ContentDocumentId);
        }
        attachmentinfo=[SELECT Title,OwnerId,ContentModifiedDate from ContentDocument WHERE id IN :fileIDs];
        // attachmentinfo =[SELECT Id, Name,OwnerId FROM Attachment WHERE  parentid =:id  ];
        if(attachmentinfo.size()>0){
            for (Integer i = 0; i < attachmentinfo.size(); i++) {
                attachmentRecoeds.add(new MaintenanceProductDataDetailsInfo(attachmentinfo[i]));
            }
        }
    }
    // 20231103 chenjingwu  Lightning文件修改 End
    public PageReference save() {
        Integer FLG = 0;
        Integer Count = 0;
@@ -636,12 +704,14 @@
                                InsAfterDel.Dealer_special_Object__c = ass.mpdrdd.Dealer_special_Object__c;
                                InsAfterDel.Key_product_147P__c = ass.mpdrdd.Key_product_147P__c;
                                InsAfterDel.Important_Endopartner_product__c = ass.mpdrdd.Important_Endopartner_product__c;
                                InsAfterDel.LastbuyProductFLG__c = ass.mpdrdd.LastbuyProductFLG__c; //kk lastbuy 20240319 add
                                //old数据
                                //InsAfterDel.Tier1_Category_Old__c = ass.Prod.Tier1_Category__c;
                                InsAfterDel.ENG_DeaerProFlag_Old__c = ass.Prod.ENG_DeaerProFlag__c;
                                InsAfterDel.Dealer_special_Object_Old__c = ass.Prod.Dealer_special_Object__c;
                                InsAfterDel.Key_product_147P_Old__c = ass.Prod.Key_product_147P__c;
                                InsAfterDel.Important_Endopartner_product_Old__c = ass.Prod.Important_Endopartner_product__c;
                                InsAfterDel.LastbuyProductFLG_Old__c = ass.Prod.LastbuyProductFLG__c; //kk lastbuy 20240319 add
                                // FY23修改 WLIG-CFV4AV 重点产品维护(新)start
                                InsAfterDel.Key_product_155P__c = ass.mpdrdd.Key_product_155P__c;
@@ -818,11 +888,61 @@
                        Ins.add(InsAfterDel);     
                    }
                }
                List<Maintenance_Product_Data_Details__c> exIntList = new List<Maintenance_Product_Data_Details__c>();
                if(mpdDetailsRecords.size() > 0 && RecordTypeName.equals('GuranteeMain')){
                    if(exmpdDetailsRecordsMap == null){
                        // chenjingwu 3+2多年保修 20240417 start
                        List<String> idList = new List<String>();
                        for(MaintenanceProductDataDetailsInfo ass :mpdDetailsRecordsView){
                            if(ass.check == true){
                                idList.add(ass.Prod.id);
                            }
                        }
                        // chenjingwu 3+2多年保修 20240417 end
                        // chenjingwu 3+2多年保修 20240417 start
                        muList = [select Id,AgeLimit__c,MultiOneYearWarrantyPrice__c,AmountWithheld__c,ProductName__r.Name,ProductName__c from MultiYearWarranty__c where ProductName__c in: idList order By ProductName__c];
                        for(MultiYearWarranty__c mu: muList){
                            Maintenance_Product_Data_Details__c insmpdd = new Maintenance_Product_Data_Details__c();
                            insmpdd.AgeLimit__c = mu.AgeLimit__c;
                            insmpdd.MultiYearWarranty__c = mu.Id;
                            insmpdd.MultiOneYearWarrantyPrice__c = mu.MultiOneYearWarrantyPrice__c;
                            insmpdd.AmountWithheld__c = mu.AmountWithheld__c;
                            insmpdd.AgeLimit_Old__c = mu.AgeLimit__c;
                            insmpdd.MultiOneYearWarrantyPrice_Old__c = mu.MultiOneYearWarrantyPrice__c;
                            insmpdd.AmountWithheld_Old__c = mu.AmountWithheld__c;
                            insmpdd.RecordTypeId = '012C50000000jefIAA';
                            exIntList.add(insmpdd);
                        }
                    } else{
                        for(List<ExMpdDetailsInfo> li: exmpdDetailsRecordsMap.values()){
                            for(ExMpdDetailsInfo ex: li){
                                Maintenance_Product_Data_Details__c InsAfterDel = new Maintenance_Product_Data_Details__c();
                                InsAfterDel.AgeLimit__c = ex.mpdrdd.AgeLimit__c;
                                InsAfterDel.MultiYearWarranty__c = ex.mpdrdd.MultiYearWarranty__c;
                                InsAfterDel.MultiOneYearWarrantyPrice__c = ex.mpdrdd.MultiOneYearWarrantyPrice__c;
                                InsAfterDel.AmountWithheld__c = ex.mpdrdd.AmountWithheld__c;
                                InsAfterDel.AgeLimit_Old__c = ex.Prod.AgeLimit__c;
                                InsAfterDel.MultiOneYearWarrantyPrice_Old__c = ex.Prod.MultiOneYearWarrantyPrice__c;
                                InsAfterDel.AmountWithheld_Old__c = ex.Prod.AmountWithheld__c;
                                InsAfterDel.RecordTypeId = '012C50000000jefIAA';
                                exIntList.add(InsAfterDel);
                            }
                        }
                    }
                    // chenjingwu 3+2多年保修   20240417 end
                }
                if(isWarning){
                    return null;
                }else{
                    if(Ins.size()>0){
                        upsert Ins;
                        upsert exIntList;
                        return setEditAble();
                    }else{
                        return null;
@@ -830,6 +950,7 @@
                }
            }
        }catch(Exception e){
            System.debug('chenjingwu==>' + e.getMessage());
            ApexPages.addMessages(e);
            Database.rollback(sp);
            return null;
@@ -885,6 +1006,8 @@
                                // 20221020 ljh SWAG-CJ98AJ start
                                upMpd.suitDepartment__c = ass.mpded.suitDepartment__c;
                                // 20221020 ljh SWAG-CJ98AJ end
                                //kk lastbuy add 20240329 start
                                upMpd.LastbuyProductFLG__c = ass.mpded.LastbuyProductFLG__c;
                            }
                            when 'GuranteeMain'{
                                upMpd.Entend_gurantee_period__c=ass.mpded.Entend_gurantee_period__c;
@@ -1095,6 +1218,7 @@
        return ref;
    }
    //上传附件
     // 20231103 陈京武  Lightning文件修改 Start
    public PageReference FilesUpload(){
        PageReference ref = new Pagereference('/p/attach/NoteAttach?pid='+id+'&retURL=%2F' + '/apex/MaintenanceProductData?id=' +id);
        ref.setRedirect(true);
@@ -1108,6 +1232,7 @@
        ref.setRedirect(true);
        return ref;
    }
    // 20231103 陈京武  Lightning文件修改 Start
    // 提交按钮
    public PageReference Submitmpd() {
        //List<Maintenance_Product_Data__c> qs = New List<Maintenance_Product_Data__c>();
@@ -1193,8 +1318,10 @@
    public PageReference returnMpdPage(){
        PageReference ref;
        if(String.isBlank(id)){
            // 20231103 陈京武  Lightning文件修改 Start
            // ref = new Pagereference(ApexPages.currentPage().getParameters().get('retURL'));
            ref = new Pagereference('/lightning/o/Maintenance_Product_Data__c/list?filterName=Recent');
            // 20231103 陈京武  Lightning文件修改 End
        }else{
            ref = new Pagereference('/'+id);
        }
@@ -1213,7 +1340,7 @@
            }
        }*/
        String soql = 'select Id ,ProductCode_Ext__c,Name   ';
        String soql = 'select Id ,ProductCode_Ext__c,Name,LastbuyProductFLG__c   ';
        if(!RecordTypeName.equals('GuranteeMain') && !RecordTypeName.equals('GuranteePrice') ){
            for (Integer i=0;i<column.size();i++) {soql += ',' + column[i];
            }
@@ -1259,7 +1386,7 @@
            soql += ' AND (GuranteeType__c like \'%'+ String.escapeSingleQuotes(GuranteeType.replaceAll('%', '\\%')) + '%\')';
        }
        soql += ' Limit 400';
        //System.debug('soql +++++++++++  ' + soql );
        System.debug('soql +++++++++++  ' + soql );
        return soql;
    }
     // 显示数据条数信息
@@ -1369,7 +1496,9 @@
        public Boolean canSelect { get; set; }
        public Product2 Prod { get; set; }
        public Maintenance_Product_Data_Details__c mpdrdd {get; set;}
        // 20231103 chenjingwu  Lightning文件修改 Start
        public ContentDocument Concc { get; set; }
        // 20231103 chenjingwu  Lightning文件修改 End
        public MaintenanceProductDataDetailsInfo(Maintenance_Product_Data_Details__c e) {
            check = true;
@@ -1386,9 +1515,11 @@
            canSelect = true;
        }
        //附件
        // 20231103 chenjingwu  Lightning文件修改 Start
        public MaintenanceProductDataDetailsInfo(ContentDocument e) {
            Concc = e;
        }
        // 20231103 chenjingwu  Lightning文件修改 End
    }
    class MpdDetailsInfo  {
        public Boolean check { get; set; }
@@ -1404,4 +1535,35 @@
        }
    }
    class ExMpdDetailsInfo  {
        public Boolean check { get; set; }
        public Boolean oldCheck { get; set; }
        public Boolean canSelect { get; set; }
        public MultiYearWarranty__c Prod { get; set; }
        public Maintenance_Product_Data_Details__c mpdrdd {get; set;}
        public ExMpdDetailsInfo(Maintenance_Product_Data_Details__c e) {
            check = true;
            oldCheck = true;
            mpdrdd = e;
            Prod = e.MultiYearWarranty__r;
            canSelect = true;
        }
        public ExMpdDetailsInfo(MultiYearWarranty__c e) {
            check = false;
            oldCheck = false;
            mpdrdd = new Maintenance_Product_Data_Details__c();
            Prod = e;
            canSelect = true;
        }
        public ExMpdDetailsInfo() {
            check = false;
            oldCheck = false;
            mpdrdd = new Maintenance_Product_Data_Details__c();
            Prod = new MultiYearWarranty__c();
            canSelect = true;
        }
    }
}