global without sharing class StraightBackAddressController2 {

    @RemoteAction
    global 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;
    }
}