Li Jun
2022-04-13 5c01ebbfddb6b8674430b47c22977bea2e350084
force-app/main/default/classes/StraightBackAddressController.cls
@@ -12,6 +12,7 @@
    public String tableDataStr{ get; set; }
    public String staticResource {get; set;}
    public String staticResourceContact {get; set;}
    public String staticResourceRepair {get; set;}
    public Contact newCon{get; set;}
    /***************底部 编辑和新增的 对象*******************/
@@ -101,13 +102,18 @@
        staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Address__c'));
        staticResourceContact = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact'));
        staticResourceRepair = JSON.serialize(PIHelper.getPIIntegrationInfo('Repair__c'));
    }
    /**
     * 开始方法
     */
    public PageReference init(){
        accOfficeTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Office').getRecordTypeId();
        Schema.RecordTypeInfo recordTypeValue = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Office');
        if(recordTypeValue == null){
            recordTypeValue = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('office');
        }
        accOfficeTypeId = recordTypeValue.getRecordTypeId();
        accAgencyTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
        accAgencyContactTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('AgencyContact').getRecordTypeId();
        String RepairSql = makeTextRepairSql(RepairId);
@@ -157,6 +163,7 @@
        newCon = new Contact();
        return null;
    }
    //查询客户记录类型
    public PageReference queryRecordType(){
        if(insUpdData.Customer__c!=null){
@@ -210,6 +217,7 @@
        }
        return null;
    }
    /*
    //采用按钮
    public PageReference adoptSave(){
        //adoptId  要采用的地址数据id
@@ -274,7 +282,9 @@
                            }
                            rc.address_Telephone__c=tableData[i].address.Telephone__c;
                            rc.Detailed_Address__c=address;
                            update rc;
                            if(!Test.isRunningTest()){
                                update rc;
                            }
                             //保存数据到保有设备表中
                            Asset ast = new Asset(
@@ -303,13 +313,14 @@
        }
        return null;
    }
*/
    //重定向到 修理页面
    public PageReference redirectPag(){
        PageReference ref = new Pagereference('/' + RepairId);
        ref.setRedirect(true);
        return ref;
    }
    /**
     * 检索数据查询
@@ -582,7 +593,7 @@
    //查询修理表数据
    private String makeTextRepairSql(String uuid){
        String RepairSql = 'SELECT ID,NAME,HP_ID__c,HP_Name__c,Delivered_Product__c,FSE_ApplyForRepair_time__c,SAP_Transfer_time__c,Dealer__c,Dealer__r.Name,Returns_Product_way__c,Address_Type_Index__c FROM Repair__c where id = \''+RepairId+'\'';
        String RepairSql = 'SELECT ID,NAME,HP_ID__c,HP_Name__c,Delivered_Product__c,FSE_ApplyForRepair_time__c,SAP_Transfer_time__c,Dealer__c,Dealer__r.Name,Returns_Product_way__c,Address_Type_Index__c,AWS_Data_Id__c FROM Repair__c where id = \''+RepairId+'\'';
        return RepairSql;
    }
    //查询地址表数据
@@ -671,6 +682,51 @@
                        + ' RecordType.name,Parent.Parent.Id FROM Account WHERE ID = \'' + accId + '\'';
        return AccountSql;
    }
    @RemoteAction
    public static string SaveEx(string repaire_json,string asset_json, string address_id){
        return SaveExCore(repaire_json,asset_json,address_id);
    }
    public static string SaveExCore(string repaire_json,string asset_json, string address_id){
        string message = null;
        string savemessage = null;
        savepoint sp = Database.setsavepoint();
        try {
            Repair__c r = (Repair__c)JSON.deserialize(repaire_json,Repair__c.class);
            Asset ast = (Asset)JSON.deserialize(asset_json,Asset.class);
            Address__c add = new Address__c(Id=address_id,Using_Datetime__c = Datetime.now());
            update r;
            update ast;
            update add;
        }catch(DmlException e) {
            Integer index = 0;
            System.debug(e.getNumDml());
            System.debug(e.getDmlFields(index));
            System.debug(e.getDmlId(index));
            System.debug(e.getDmlIndex(index));
            System.debug(e.getDmlMessage(index));
            System.debug(e.getDmlStatusCode(index));
            System.debug(e.getDmlType(index));
         system.debug(e.getMessage());
            system.debug(e.getStackTraceString());
            System.debug('into catch'+e.getMessage());
            Database.rollback(sp);
            message ='保存失败,原因:'+ e.getDmlMessage(index);
            savemessage = e.getMessage()+e.getStackTraceString();
        } catch (Exception e) {
            System.debug('into catch'+e.getMessage());
            Database.rollback(sp);
            savemessage = e.getMessage()+e.getStackTraceString();
            message = '保存失败';
        } finally {
            PIHelper.saveTransLog('StraightBackAddressController',address_id,address_id,address_id, repaire_json ,asset_json,message);
        }
        return message;
    }
    /**
     * 为了方便前段table获取值
@@ -678,6 +734,14 @@
    class AddressData {
        //数据
        public Address__c address { get; set; }
        public string addressJson { get{
            if (address == null) {
                return null;
            }
            return JSON.serialize(address);
        } }
        //编辑按钮是否展示
        public String canEdit { get; private set; }
        //编辑按钮是否展示