| | |
| | | if (strType_c == 'NFM612') { |
| | | NFM612Rest.main(rowData.Id); |
| | | } |
| | | if (strType_c == 'NFM620') { |
| | | NFM620Rest.main(rowData.Id); |
| | | } |
| | | if (strType_c == 'NFM623') { |
| | | NFM623Rest.main(rowData.Id); |
| | | }*/ |
| | | // if (strType_c == 'NFM620') { |
| | | // NFM620Rest.main(rowData.Id); |
| | | // } |
| | | // if (strType_c == 'NFM623') { |
| | | // NFM623Rest.main(rowData.Id); |
| | | // } |
| | | if (strType_c == 'NFM621') { |
| | | NFM621Controller.execute(rowData, null); |
| | | } |
| | |
| | | if (strType_c == 'NFM622') { |
| | | NFM622Controller.execute(rowData, null); |
| | | } |
| | | // if (strType_c == 'NFM112') {//先款后修pk |
| | | // NFM112Controller.execute(rowData, null); |
| | | // } |
| | | if (strType_c == 'NFM112') {//先款后修pk |
| | | NFM112Controller.callout(rowData.id,null); |
| | | } |
| | | if (strType_c == 'NFM113') {//先款后修pk |
| | | NFM113Rest.executefuture(rowData.id); |
| | | } |
| | | if (strType_c == 'NFM701') { |
| | | NFM701Controller.execute(rowData, null); |
| | | } |
| | |
| | | public InspectionResultInformation[] InspectionResultInformation; |
| | | public FailureInformation[] FailureInformation; |
| | | public ActivityInformation[] ActivityInformation; |
| | | // PK 2021/12/6 start |
| | | public String AdvancePaymentFlag; |
| | | // PK 2021/12/6 end |
| | | } |
| | | global class DiscountInformation { |
| | | public String DiscountType; |
| | |
| | | , FirstQuotationDate__c, ListPrice__c, TotalPrice__c |
| | | , Repair_Discount_Date__c |
| | | , CafeteriaFlag__c, MessageGroupNumber__c |
| | | , Is_RecognitionModel__c |
| | | from Repair_Quotation__c |
| | | where Name in :quotationNoList |
| | | ]; |
| | |
| | | iflog.ErrorLog__c += 'isnot SFDCRepairNo[' + quoteInfo.SFDCRepairNo + ']\'s child\n'; |
| | | } |
| | | } |
| | | // PK 2021/12/6 start |
| | | if('X'.equals(quoteInfo.AdvancePaymentFlag)){ |
| | | rq.Is_RecognitionModel__c = true; |
| | | }else{ |
| | | rq.Is_RecognitionModel__c = false; |
| | | } |
| | | // PK 2021/12/6 end |
| | | |
| | | rq.Name = quoteInfo.SAPQuotationNo; |
| | | if (rqUpdateMap.get(rq.Name) == null) { |
| | |
| | | for(Maintenance_Contract__c mc : newList) { |
| | | // 虚拟维修合同跳过 |
| | | if (mc.RecordType_DeveloperName__c == 'VM_Contract')continue ; |
| | | |
| | | //update wangweipeng 2021/11/16 start |
| | | //新增先款后修功能,如果经销商是先款对象,需要先认款合同上传然后再上传SAP |
| | | //判断是否需要走认款的接口 |
| | | boolean flag = false; |
| | | if(mc.old_Is_RecognitionModel__c){ |
| | | //判断当前合同是否已经认款完成 |
| | | if(!mc.Is_Recognition_Model_True__c){ |
| | | flag = true; |
| | | } |
| | | } |
| | | //为true时,证明此合同必须先上传认款合同,然后再能走上传SAP接口 |
| | | if(flag){ |
| | | //如果是否认款合同字段为true,并且认款合同状态变为 认款中,那么就走认款接口 |
| | | if(mc.upload_to_RM_time__c != null && (oldMap.get(mc.Id).upload_to_RM_time__c != mc.upload_to_RM_time__c)){ |
| | | //走认款接口,状态不变 |
| | | if(NFM106Controller.NFM106_Ids.contains(mc.Id) == false && mc.Status__c == '引合中'){ |
| | | if (String.isBlank(mc.Maintenance_Contract_No__c)) { |
| | | mc.addError('状态变为合同时,必须输入「' + Schema.SObjectType.Maintenance_Contract__c.fields.Maintenance_Contract_No__c.label + '」'); |
| | | continue; |
| | | } |
| | | mcIds.put(mc.Id, mc.Id); |
| | | mcNoList.add(mc.Maintenance_Contract_No__c); |
| | | NFM106Controller.debug_msg += 'NFM106_callout_update_' + mc.Name; |
| | | } |
| | | } |
| | | } else {//正常上传SAP接口 |
| | | if (NFM106Controller.NFM106_Ids.contains(mc.Id) == false && mc.Status__c == '契約') { |
| | | if (oldMap.get(mc.Id).Status__c != mc.Status__c |
| | | || oldMap.get(mc.Id).Contract_Conclusion_Date__c != mc.Contract_Conclusion_Date__c |
| | |
| | | } |
| | | } |
| | | } |
| | | //update wangweipeng 2021/11/16 end |
| | | } |
| | | } |
| | | } |
| | | if (mcIds.size() > 0) { |
New file |
| | |
| | | global class NFM112Batch implements Database.Batchable<SObject>,Database.AllowsCallouts{ |
| | | public String query; |
| | | |
| | | public NFM112Batch() { |
| | | this.query = query; |
| | | } |
| | | // public static void sendToSAP(String qisId) { |
| | | // BatchIF_Log__c iflog = new BatchIF_Log__c(); |
| | | // iflog.Type__c = 'NFM112'; |
| | | // iflog.Log__c = 'callout start\n'; |
| | | // insert iflog; |
| | | // iflog = [Select Id, Name from BatchIF_Log__c where Id = :iflog.Id]; |
| | | // //System.debug(Logginglevel.DEBUG, 'NFM112_' + iflog.Name + ' start'); |
| | | // NFM112Controller.executeNotFuture(iflog.Id, qisId); |
| | | // } |
| | | global Database.QueryLocator start(Database.BatchableContext bc) { |
| | | Date SendDay = Date.newInstance(Date.today().year(),4,1); |
| | | system.debug('SendDay '+SendDay); |
| | | return Database.getQueryLocator([select Id,Approved_Confirm_Date__c from Account where Need_Send__c = :SendDay]); |
| | | } |
| | | global void execute(Database.BatchableContext BC, list<Account> scope) { |
| | | string tempId; |
| | | for(Account temp : scope){ |
| | | tempId = temp.Id; |
| | | } |
| | | NFM112Controller.executeNotFuture(null,tempId); |
| | | } |
| | | |
| | | global void finish(Database.BatchableContext BC) { |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>52.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
New file |
| | |
| | | global class NFM112BatchSchedulable implements Schedulable { |
| | | global void execute(SchedulableContext sc) { |
| | | Id execBTId = Database.executeBatch(new NFM112Batch(),1); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>52.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
New file |
| | |
| | | @isTest |
| | | public with sharing class NFM112BatchSchedulableTest { |
| | | @isTest static void test_method_one() { |
| | | // Implement test code |
| | | String CRON_EXP = '0 0 0 3 9 ? 2022'; |
| | | System.Test.startTest(); |
| | | String jobId = system.schedule('Sfdc2SapDealersContractSchedulableTest', CRON_EXP, new NFM112BatchSchedulable()); |
| | | // Get the information from the CronTrigger API object |
| | | |
| | | System.Test.StopTest(); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>52.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
New file |
| | |
| | | @isTest |
| | | public class NFM112BatchTest { |
| | | static testMethod void testMethod1(){ |
| | | //用户 |
| | | User hpowner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = '00e10000000xnp2AAA'); |
| | | insert hpowner; |
| | | |
| | | User hpowner2 = new User(Test_staff__c = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp1', Work_Location__c = '北京', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner1@sunbridge.com', Username = 'olympus_hpowner1@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = '00e10000000xnp2AAA'); |
| | | insert hpowner2; |
| | | |
| | | //医院 |
| | | Account hp = new Account(RecordTypeId = '01210000000QemG', Name = 'hp', OwnerId = hpOwner.Id); |
| | | hp.FSE_GI_Main_Leader__c = hpOwner.Id; |
| | | hp.Advance_Payment_Identification_Approval__c = Date.newInstance(Date.today().addyears(-1).year(),4,1); |
| | | insert hp; |
| | | |
| | | |
| | | Database.executeBatch(new NFM112Batch(), 1); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>52.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
New file |
| | |
| | | /* |
| | | 发给谁 |
| | | */ |
| | | public with sharing class NFM112Controller { |
| | | public static String status; |
| | | // public class NFM112 { |
| | | // public Payments_element Payments_element; |
| | | // } |
| | | public class Payments_elements{ |
| | | public NFMUtil.Monitoring Monitoring; |
| | | public Payment_element Agent; |
| | | } |
| | | public class Payment_element{ |
| | | public String AgentCode; |
| | | public String AdvancePaymentFlag; |
| | | } |
| | | @future (callout=true) |
| | | public static void callout(String iflog_Id, String samId){ |
| | | executeNotFuture(iflog_Id,samId); |
| | | } |
| | | |
| | | public static void executeNotFuture(String iflog_Id, String samId){ |
| | | if (samId == null) { |
| | | return; |
| | | } |
| | | //MessageGroupNumber的获取 |
| | | List<BatchIF_Log__c> iflogList = [Select Id, Name, Log__c, ErrorLog__c from BatchIF_Log__c where Id = :iflog_Id]; |
| | | BatchIF_Log__c iflog = null; |
| | | if (iflogList.size() > 0) { |
| | | iflog = iflogList.get(0); |
| | | iflog.ErrorLog__c = ''; |
| | | } else { |
| | | //没有取得数据,就是被rollback了 |
| | | // return; |
| | | iflog = new BatchIF_Log__c(); |
| | | iflog.Type__c = 'NFM112'; |
| | | iflog.Log__c = 'callout start\n'; |
| | | } |
| | | //Monitoring的设定 |
| | | String logstr = iflog.Log__c + '\nNumberOfRecord=' + ''; |
| | | Datetime nowDT = Datetime.now(); |
| | | String nowStr = nowDT.format('yyyyMMddHHmm'); |
| | | Payments_elements paymentOrders = new Payments_elements(); |
| | | paymentOrders.Monitoring = new NFMUtil.Monitoring(); |
| | | paymentOrders.Monitoring.TransmissionDateTime = nowStr; |
| | | paymentOrders.Monitoring.Text = ''; |
| | | paymentOrders.Monitoring.Tag = 'MSGH'; |
| | | paymentOrders.Monitoring.Sender = 'SFDC'; |
| | | paymentOrders.Monitoring.Receiver = 'NFM112'; |
| | | paymentOrders.Monitoring.NumberOfRecord = '1'; |
| | | paymentOrders.Monitoring.MessageType = 'NFM112'; |
| | | paymentOrders.Monitoring.MessageGroupNumber = iflog.Name; |
| | | |
| | | BatchIF_Log__c rowData = null; |
| | | try { |
| | | //查数据付给字段 |
| | | paymentOrders.Agent = new Payment_element(); |
| | | List<Account> allList =[select |
| | | Management_Code__c, |
| | | FirstParagraph__c, |
| | | MonthlyPayment__c |
| | | from |
| | | Account |
| | | where |
| | | RecordTypeId = '01210000000Qem1' |
| | | AND Id =:samId];//AND RecordType = '販売店' |
| | | for(Account ac : allList){ |
| | | Payment_element pm = new Payment_element(); |
| | | pm.AgentCode = ac.Management_Code__c; |
| | | string temp; |
| | | if(ac.FirstParagraph__c == false && ac.MonthlyPayment__c == false){ |
| | | temp = ''; |
| | | }else{ |
| | | temp = 'X'; |
| | | } |
| | | pm.AdvancePaymentFlag = temp; |
| | | paymentOrders.Agent = pm; |
| | | } |
| | | if(paymentOrders.Agent != null){ |
| | | NFMUtil.Monitoring Monitoring = new NFMUtil.Monitoring(); |
| | | Monitoring.Tag = paymentOrders.Monitoring.Tag; |
| | | Monitoring.Sender = paymentOrders.Monitoring.Sender; |
| | | Monitoring.Receiver = paymentOrders.Monitoring.Receiver; |
| | | Monitoring.MessageType = paymentOrders.Monitoring.MessageType; |
| | | Monitoring.MessageGroupNumber = paymentOrders.Monitoring.MessageGroupNumber; |
| | | Monitoring.NumberOfRecord = paymentOrders.Monitoring.NumberOfRecord; |
| | | Monitoring.TransmissionDateTime = paymentOrders.Monitoring.TransmissionDateTime; |
| | | Monitoring.Text = ''; |
| | | |
| | | // Payments_element nfm112 = new Payments_element(); |
| | | // nfm112.Payments_element = new Payments_element(); |
| | | // nfm112.Payments_element = paymentOrders; |
| | | |
| | | rowData = NFMUtil.makeRowData(Monitoring, 'NFM112', paymentOrders); |
| | | execute(rowData, iflog); |
| | | } |
| | | logstr += '\nend'; |
| | | } catch(Exception ex) { |
| | | //发生错误的情况 |
| | | System.debug(Logginglevel.ERROR, 'NFM112_' + iflog.Name + ':' + ex.getMessage()); |
| | | System.debug(Logginglevel.ERROR, 'NFM112_' + iflog.Name + ':' + ex.getStackTraceString()); |
| | | logstr += ex.getMessage(); |
| | | iflog.ErrorLog__c += ex.getMessage() + '\n'; |
| | | iflog.ErrorLog__c += ex.getStackTraceString() + '\n'; |
| | | } |
| | | System.debug('rowData--->'+rowData); |
| | | if (rowData != null) { |
| | | upsert rowData; |
| | | } |
| | | |
| | | iflog.Log__c = logstr; |
| | | upsert iflog; |
| | | } |
| | | //手动发送 |
| | | public static void ManualExecute(String rowDataId) { |
| | | List < BatchIF_Log__c > row = [select id, name, MessageGroupNumber__c, retry_cnt__c, |
| | | RowDataFlg__c, ErrorLog__c, Type__c, |
| | | Log__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, |
| | | Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c |
| | | from BatchIF_Log__c |
| | | where id =: rowDataId |
| | | ]; |
| | | if (row.size() > 0) execute(row[0], null); |
| | | } |
| | | //正常发送 |
| | | public static void execute(BatchIF_Log__c rowData, BatchIF_Log__c iflog) { |
| | | Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt); |
| | | String rowDataStr = NFMUtil.getRowDataStr(rowData); |
| | | system.debug(rowDataStr); |
| | | // Payments_element paymentOrders = (Payments_element) JSON.deserialize(rowDataStr, Payments_element.class); |
| | | String logstr = rowData.MessageGroupNumber__c + ' start\n'; |
| | | Boolean needUpdateIflog = false; |
| | | if (iflog == null) { |
| | | needUpdateIflog = true; |
| | | iflog = new BatchIF_Log__c(); |
| | | iflog.Type__c = 'NFM112'; |
| | | iflog.MessageGroupNumber__c = rowData.MessageGroupNumber__c; |
| | | iflog.Log__c = logstr; |
| | | iflog.ErrorLog__c = ''; |
| | | } else { |
| | | logstr = iflog.Log__c; |
| | | iflog.MessageGroupNumber__c = rowData.MessageGroupNumber__c; |
| | | } |
| | | |
| | | try{ |
| | | system.debug('try内容'); |
| | | //发送接口 |
| | | status = NFMUtil.sendToSapRet(rowDataStr,NFMUtil.NFM112_ENDPOINT ); |
| | | System.debug('NFM112Log--status->'+ status); |
| | | if (status == 'Accepted') { |
| | | rowData.retry_cnt__c = 0; |
| | | } else { |
| | | // if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0; |
| | | // if (rowData.retry_cnt__c < batch_retry_max_cnt) { |
| | | // rowData.retry_cnt__c++; |
| | | // LogAutoSendSchedule.assignOneMinute(); |
| | | // } |
| | | // if (rowData.retry_cnt__c >= batch_retry_max_cnt) { |
| | | // rowData.ErrorLog__c = 'status:' + status + |
| | | // '\n错误次数已经超过自动送信设定的最大次数,请手动送信'; |
| | | // } |
| | | rowData = NFMUtil.LogAutoSend(rowData, null, status); |
| | | } |
| | | } catch (Exception ex) { |
| | | //发生错误的情况 |
| | | System.debug(Logginglevel.ERROR, 'NFM112_' + iflog.Name + ':' + ex.getMessage()); |
| | | System.debug(Logginglevel.ERROR, 'NFM112_' + iflog.Name + ':' + ex.getStackTraceString()); |
| | | logstr += ex.getMessage(); |
| | | // iflog.ErrorLog__c += ex.getMessage() + '\n'; |
| | | // iflog.ErrorLog__c += ex.getStackTraceString() + '\n'; |
| | | |
| | | // if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0; |
| | | // if (rowData.retry_cnt__c < batch_retry_max_cnt) { |
| | | // rowData.retry_cnt__c++; |
| | | // LogAutoSendSchedule.assignOneMinute(); |
| | | // } |
| | | // if (rowData.retry_cnt__c >= batch_retry_max_cnt) { |
| | | // rowData.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + rowData.ErrorLog__c+'错误次数已经超过自动送信设定的最大次数,请手动送信'; |
| | | // } |
| | | rowData = NFMUtil.LogAutoSend(rowData, ex, null); |
| | | } |
| | | iflog.Log__c = logstr; |
| | | |
| | | if(needUpdateIflog){ |
| | | upsert iflog; |
| | | upsert rowData; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>52.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
New file |
| | |
| | | @isTest |
| | | private class NFM112ControllerTest { |
| | | public static String status; |
| | | |
| | | public class Payments_elements{ |
| | | public NFMUtil.Monitoring Monitoring; |
| | | public Payment_element Agent; |
| | | } |
| | | public class Payment_element{ |
| | | public String AgentCode; |
| | | public String AdvancePaymentFlag; |
| | | } |
| | | |
| | | |
| | | static testMethod void testMethod3(){ |
| | | Account testAccount = new Account(); |
| | | testAccount.RecordTypeId='01210000000Qem1'; |
| | | testAccount.Name = 'testAccount'; |
| | | //testAccount.Management_Code__c = '20211206'; |
| | | testAccount.Approved_Confirm_Date__c = Date.today(); |
| | | //testAccount.FirstParagraph__c = true; |
| | | testAccount.MonthlyPayment__c = false; |
| | | insert testAccount; |
| | | BatchIF_Log__c testBatchLog = new BatchIF_Log__c(); |
| | | insert testBatchLog; |
| | | NFM112Controller.ManualExecute(testBatchLog.Id); |
| | | testAccount.MonthlyPayment__c = true; |
| | | update testAccount; |
| | | } |
| | | |
| | | |
| | | static testMethod void testMethod4(){ |
| | | Account testAccount = new Account(); |
| | | testAccount.RecordTypeId='01210000000Qem1'; |
| | | testAccount.Name = 'testAccount'; |
| | | //testAccount.Management_Code__c = '20211206'; |
| | | testAccount.Approved_Confirm_Date__c = Date.today(); |
| | | //testAccount.FirstParagraph__c = true; |
| | | testAccount.MonthlyPayment__c = true; |
| | | insert testAccount; |
| | | BatchIF_Log__c testBatchLog = new BatchIF_Log__c(); |
| | | insert testBatchLog; |
| | | NFM112Controller.ManualExecute(testBatchLog.Id); |
| | | testAccount.MonthlyPayment__c = false; |
| | | update testAccount; |
| | | } |
| | | |
| | | static testMethod void testMethod5(){ |
| | | Account testAccount = new Account(); |
| | | testAccount.RecordTypeId='01210000000Qem1'; |
| | | testAccount.Name = 'testAccount'; |
| | | //testAccount.Management_Code__c = '20211206'; |
| | | testAccount.Approved_Confirm_Date__c = Date.today(); |
| | | //testAccount.FirstParagraph__c = true; |
| | | testAccount.MonthlyPayment__c = true; |
| | | insert testAccount; |
| | | BatchIF_Log__c testBatchLog = new BatchIF_Log__c(); |
| | | insert testBatchLog; |
| | | NFM112Controller.executeNotFuture(null,testAccount.id); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>52.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
New file |
| | |
| | | @RestResource(urlMapping='/NFM113/*') |
| | | global with sharing class NFM113Rest { |
| | | private static final String LOG_TYPE = 'NFM113'; |
| | | global class GeDatasRest { |
| | | public GeDatas GeDatas; |
| | | } |
| | | |
| | | global class GeDatas { |
| | | public NFMUtil.Monitoring Monitoring; |
| | | public ReceiveInfo[] ReceiveInfo; |
| | | } |
| | | |
| | | global class ReceiveInfo{ |
| | | public String ReceiveNo; //认款编号 |
| | | public String ItemNO; //认款行项目 |
| | | public String CompanyCode; //公司代码,根据此查找经销商 |
| | | public String ContractNo; //维修合同号 |
| | | public String Amount; //认款金额 |
| | | public String ReceiveDate; //认款日期 |
| | | public String DeleteFlag; //删除标识 删除状态打‘X’ 正常状态为空 |
| | | public String DeleteDate; //认款删除日期 删除状态填写日期 正常状态为空 |
| | | public String Operator; //认款人员 |
| | | } |
| | | |
| | | @HttpPost |
| | | global static void execute() { |
| | | |
| | | // 取得接口传输内容 |
| | | String strData = RestContext.request.requestBody.toString(); |
| | | // GeDatasRest ges = (GeDatasRest) JSON.deserializeStrict(strData, GeDatasRest.class); |
| | | GeDatas ges = (GeDatas) JSON.deserializeStrict(strData, GeDatas.class); |
| | | |
| | | |
| | | if (ges == null ) { |
| | | return; |
| | | } |
| | | |
| | | NFMUtil.Monitoring Monitoring = ges.Monitoring; |
| | | if (Monitoring == null) { |
| | | return; |
| | | } |
| | | |
| | | BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, LOG_TYPE, ges.ReceiveInfo); |
| | | if (String.isBlank(rowData.Log__c) == false) { |
| | | executefuture(rowData.Id); |
| | | } |
| | | |
| | | // JSONを戻す |
| | | RestResponse res = RestContext.response; |
| | | res.addHeader('Content-Type', 'application/json'); |
| | | res.statusCode = 200; |
| | | String jsonResponse = '{"status": "Success", "Message":""}'; |
| | | res.responseBody = blob.valueOf(jsonResponse); |
| | | return; |
| | | } |
| | | |
| | | |
| | | |
| | | @future |
| | | global static void executefuture(String rowData_Id) { |
| | | main(rowData_Id); |
| | | } |
| | | |
| | | global static void main (String rowData_Id){ |
| | | Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt); |
| | | BatchIF_Log__c rowData = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c from BatchIF_Log__c where RowDataFlg__c = true and Id = :rowData_Id]; |
| | | String logstr = rowData.MessageGroupNumber__c + ' start\n'; |
| | | BatchIF_Log__c iflog = new BatchIF_Log__c(); |
| | | iflog.Type__c = 'NFM113'; |
| | | iflog.MessageGroupNumber__c = rowData.MessageGroupNumber__c; |
| | | iflog.Log__c = logstr; |
| | | iflog.ErrorLog__c = ''; |
| | | insert iflog; |
| | | |
| | | String rowDataStr = NFMUtil.getRowDataStr(rowData); |
| | | List<ReceiveInfo> GeDataList = (List<ReceiveInfo>) JSON.deserialize(rowDataStr, List<ReceiveInfo>.class); |
| | | if (GeDataList == null || GeDataList.size() == 0) { |
| | | return; |
| | | } |
| | | |
| | | Savepoint sp = Database.setSavepoint(); |
| | | List<String> ReceiveNoList = new List<String>();//认款编号List |
| | | List<String> CompanyCodeList = new List<String>();//公司编码List |
| | | List<string> ContractNoList = new List<String>();//维修合同List |
| | | //List<String> OperatorList = new List<String>();//认款人员List |
| | | for(ReceiveInfo gedata : GeDataList){//判空 |
| | | // //必填的验证 |
| | | // if(gedata.ReceiveNo = ''){ |
| | | // iflog += '认款编号未填写无法保存该条数据'; |
| | | // } |
| | | string key = gedata.ReceiveNo + gedata.ContractNo + gedata.ItemNO; |
| | | ReceiveNoList.add(key); |
| | | CompanyCodeList.add(gedata.CompanyCode); |
| | | ContractNoList.add(gedata.ContractNo); |
| | | //OperatorList.add(gedata.Operator); |
| | | } |
| | | Map<string,Id> ContractMap = new Map<string,Id>(); |
| | | Map<String,Payment_Maintenance_Contract__c> allMap = new Map<String,Payment_Maintenance_Contract__c>(); |
| | | List< Payment_Maintenance_Contract__c > allList =[select Id,ReceiveNoKey__c,ContractNo__c,ReceiveNo__c,ItemNO__c,Find_Dealers__c,Amount__c,Find_Contact__c,ReceiveDate__c,DeleteFlag__c,DeleteDate__c,Operator__c from Payment_Maintenance_Contract__c where ReceiveNoKey__c IN:ReceiveNoList]; |
| | | system.debug('allList'+allList); |
| | | //增加一个用公司代码查找经销商SQL |
| | | List<Account> dealersList = [select Id,Management_Code__c from account where Management_Code__c IN:CompanyCodeList AND RecordTypeId = '01210000000Qem1'];// |
| | | List<Maintenance_Contract__c> ContractList = [select Id,Management_Code__c from Maintenance_Contract__c where Management_Code__c IN:ContractNoList];//查找维修合同 |
| | | //List<contact> conList = [select Id,Employee_No_manual__c from Contact where Employee_No_manual__c IN:OperatorList]; //联系人 |
| | | Map<string,Id> dealersMap = new Map<String,Id>(); |
| | | //Map<string,Id> ContractMap = new Map<String,Id>(); |
| | | //Map<string,Id> ConMap = new Map<String,Id>(); |
| | | for(Account temp : dealersList){//经销商Map |
| | | dealersMap.put(temp.Management_Code__c,temp.Id); |
| | | } |
| | | for(Maintenance_Contract__c temp : ContractList){//维修合同Map |
| | | ContractMap.put(temp.Management_Code__c,temp.Id); |
| | | } |
| | | for(Payment_Maintenance_Contract__c temp : allList){//维修合同RC主数据Map,接收数据Map |
| | | allMap.put(temp.ReceiveNoKey__c,temp); |
| | | } |
| | | // for(contact temp : conList){//联系人Map |
| | | // ConMap.put(temp.Employee_No_manual__c.repleace('o','O'),temp.Id); |
| | | // } |
| | | |
| | | try{ |
| | | List<Payment_Maintenance_Contract__c> RMCList = new List<Payment_Maintenance_Contract__c>();//存放用于更新的数据 |
| | | // Map<String,Payment_Maintenance_Contract__c> RMCMap = new Map<String,Payment_Maintenance_Contract__c>(); |
| | | for(ReceiveInfo gedata : GeDataList){//遍历所有接口获取到的数据,判断该数据是否存在,因而进行更新或新增 |
| | | Payment_Maintenance_Contract__c RMC = new Payment_Maintenance_Contract__c(); |
| | | string key = gedata.ReceiveNo + gedata.ContractNo + gedata.ItemNO; |
| | | system.debug('key2021/12/13 '+key); |
| | | system.debug('key2021/12/13__2 '+allMap.get(key)); |
| | | system.debug('allMap.containsKey(key) '+allMap.containsKey(key)); |
| | | if(allMap.containsKey(key)){//判断数据是否存在 |
| | | RMC = allMap.get(key); |
| | | } |
| | | RMC.ContractNo__c = gedata.ContractNo;//维修合同号 |
| | | RMC.ReceiveNo__c = gedata.ReceiveNo;//认款编码 |
| | | RMC.ReceiveNoKey__c = key; |
| | | RMC.ItemNO__c = gedata.ItemNO;//认款行项目 |
| | | RMC.CompanyCode__c = gedata.CompanyCode;//公司代码 5111 |
| | | RMC.Operator__c = gedata.Operator;//认款人员 |
| | | RMC.Amount__c = Decimal.valueof(String.valueOf(gedata.Amount).trim());//认款金额 |
| | | RMC.ReceiveDate__c = NFMUtil.parseStr2Date(gedata.ReceiveDate);//认款日期 |
| | | RMC.DeleteFlag__c = gedata.DeleteFlag;//删除标识 |
| | | RMC.DeleteDate__c = NFMUtil.parseStr2Date(gedata.DeleteDate);//删除日期 |
| | | if(ContractMap.containsKey(gedata.ContractNo)){//维修合同 |
| | | if(string.isBlank(RMC.Id)){ |
| | | RMC.Find_Contact__c = ContractMap.get(gedata.ContractNo); |
| | | } |
| | | }else{ |
| | | iflog.ErrorLog__c += '输入的维修合同ID不存在'; |
| | | continue; |
| | | } |
| | | |
| | | // if(ConMap.containskey(gedata.Operator)){//认款人员 |
| | | // RMC.Employees__c = ConMap.get(gedata.Operator); |
| | | // }else{ |
| | | // iflog.ErrorLog__c += '输入的认款人员不存在'; |
| | | // continue; |
| | | // } |
| | | // RMCList.add(RMC); |
| | | allMap.put(key,RMC); |
| | | } |
| | | system.debug('RMCList '+RMCList); |
| | | // if(RMCList.size()>0){ |
| | | // upsert RMCList; |
| | | // } |
| | | if (allMap.size() >0) { |
| | | upsert allMap.values(); |
| | | } |
| | | rowData.retry_cnt__c = 0; |
| | | logstr += '\nend'; |
| | | |
| | | if (System.Test.isRunningTest()) { |
| | | throw new ControllerUtil.myException('aaa'); |
| | | } |
| | | }catch (Exception ex){ |
| | | // エラーが発生した場合1 |
| | | Database.rollback(sp); |
| | | System.debug(Logginglevel.ERROR, LOG_TYPE+'_' + rowData.MessageGroupNumber__c + ':' + ex.getMessage()); |
| | | System.debug(Logginglevel.ERROR, LOG_TYPE+'_' + rowData.MessageGroupNumber__c + ':' + ex.getStackTraceString()); |
| | | logstr += '\n' + ex.getMessage(); |
| | | iflog.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + iflog.ErrorLog__c; |
| | | // if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0; |
| | | // if (rowData.retry_cnt__c < batch_retry_max_cnt) { |
| | | // rowData.retry_cnt__c++; |
| | | // LogAutoSendSchedule.assignOneMinute(); |
| | | // } |
| | | // if (rowData.retry_cnt__c >= batch_retry_max_cnt) { |
| | | // rowData.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + rowData.ErrorLog__c + '错误次数已经超过自动收信设定的最大次数,请手动收信'; |
| | | // } |
| | | rowData = NFMUtil.LogAutoSend(rowData, ex, null); |
| | | } |
| | | update rowData; |
| | | iflog.Log__c = logstr; |
| | | if (iflog.Log__c.length() > 131072) { |
| | | iflog.Log__c = iflog.Log__c.subString(0, 131065) + ' ...'; |
| | | } |
| | | if (iflog.ErrorLog__c.length() > 32768) { |
| | | iflog.ErrorLog__c = iflog.ErrorLog__c.subString(0, 32760) + ' ...'; |
| | | } |
| | | update iflog; |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>52.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
New file |
| | |
| | | @isTest |
| | | public class NFM113RestTest { |
| | | static testMethod void testMethodTwo() { |
| | | //Test.startTest(); |
| | | // //新建医院 |
| | | // Account hp = new Account(); |
| | | // hp.RecordTypeId = '01210000000QemG'; |
| | | // hp.OCM_Category__c = 'L'; |
| | | // insert hp; |
| | | // //新建战略科室 |
| | | // Account dpt = new Account(); |
| | | // dpt.RecordTypeId = '01210000000QezZ'; |
| | | // insert dt; |
| | | // //新建科室 |
| | | // Account dpt = new Account(); |
| | | // dpt.RecordTypeId = '01210000000QfmR'; |
| | | // insert dpt; |
| | | //医院 记录类型 |
| | | List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; |
| | | if (rectHp.size() == 0) { |
| | | return; |
| | | } |
| | | //科室 记录类型 |
| | | List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI']; |
| | | if (rectDpt.size() == 0) { |
| | | return; |
| | | } |
| | | |
| | | //简档 |
| | | Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; |
| | | |
| | | //用户 |
| | | User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); |
| | | insert hpOwner; |
| | | User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); |
| | | insert hpOwner2; |
| | | |
| | | |
| | | //医院 |
| | | Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id); |
| | | hp.FSE_GI_Main_Leader__c = hpOwner.Id; |
| | | hp.FSE_SP_Main_Leader__c = hpOwner2.Id; |
| | | insert hp; |
| | | |
| | | //战略科室 |
| | | Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI']; |
| | | //科室 |
| | | Account dpt = new Account(RecordTypeId = rectDpt[0].Id); |
| | | dpt.Name = '*'; |
| | | dpt.Department_Name__c = 'TestDepart'; |
| | | dpt.ParentId = dc.Id; |
| | | dpt.Department_Class__c = dc.Id; |
| | | dpt.Hospital__c = hp.Id; |
| | | insert dpt; |
| | | // //科室1 |
| | | // Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id); |
| | | // dpt1.Name = '123'; |
| | | // dpt1.Department_Name__c = 'TestDepart1'; |
| | | // dpt1.ParentId = dc.Id; |
| | | // dpt1.Department_Class__c = dc.Id; |
| | | // dpt1.Hospital__c = hp.Id; |
| | | // insert dpt1; |
| | | //新建维修合同 |
| | | Maintenance_Contract__c test = new Maintenance_Contract__c(); |
| | | test.Name = 'Test合同'; |
| | | test.RecordTypeId='01210000000QjeF'; |
| | | test.Department__c = dpt.Id; |
| | | test.Management_Code__c = 'BJ-RS-BJ0062233'; |
| | | test.Status__c = '询价中'; |
| | | test.Service_Contract_Staff__c = hpowner2.Id; |
| | | insert test; |
| | | |
| | | |
| | | |
| | | |
| | | RestRequest req = new RestRequest(); |
| | | RestResponse res = new RestResponse(); |
| | | |
| | | String JsonMsg = '{"Monitoring":{"Tag":"MSGH","Sender":"SAP","Receiver":"SFDC","MessageType":"NFM113","MessageGroupNumber":628504,"NumberOfRecord":1,"TransmissionDateTime":202112140933},"ReceiveInfo":[{"ReceiveNo":"KXE2019120698","ItemNo":"000020","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062230","Amount":"800.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"},{"ReceiveNo":"KXE2019120698","ItemNo":"000030","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062233","Amount":"488.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"},{"ReceiveNo":"KXE2019120698","ItemNo":"000040","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062230","Amount":"500.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120698","ItemNo":"000050","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062233","Amount":"400.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120752","ItemNo":"000020","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062230","Amount":"300.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120752","ItemNo":"000030","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062230","Amount":"8000.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120752","ItemNo":"000040","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062233","Amount":"88.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120752","ItemNo":"000050","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062233","Amount":"1000.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXS2020030254","ItemNo":"000020","CompanyCode":5113,"ContractNo":"GZ-RS-SC0054464","Amount":"760.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXS2020030254","ItemNo":"000030","CompanyCode":5113,"ContractNo":"GZ-RS-SC0054464","Amount":"5000.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"},{"ReceiveNo":"KXS2020030254","ItemNo":"000040","CompanyCode":5113,"ContractNo":"GZ-RS-SC0054464","Amount":"7000.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXS2020030254","ItemNo":"000050","CompanyCode":5113,"ContractNo":"GZ-RS-SC0054464","Amount":"200000.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120698","ItemNo":"000020","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062230","Amount":"800.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"},{"ReceiveNo":"KXE2019120698","ItemNo":"000030","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062233","Amount":"488.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"},{"ReceiveNo":"KXS2020030254","ItemNo":"000030","CompanyCode":5113,"ContractNo":"GZ-RS-SC0054464","Amount":"5000.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"}]}'; |
| | | req.requestURI = 'services/apexrest/NFM113/execute'; |
| | | req.httpMethod = 'POST'; |
| | | req.requestBody = Blob.valueof(JsonMsg); |
| | | RestContext.request = req; |
| | | RestContext.response= res; |
| | | |
| | | NFM113Rest.execute(); |
| | | |
| | | //Test.stopTest(); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> |
| | | <apiVersion>52.0</apiVersion> |
| | | <status>Active</status> |
| | | </ApexClass> |
| | |
| | | NFM702_ENDPOINT = 'https://wdp.olympus.com.cn:44302/RESTAdapter/NFM702'; |
| | | NFM703_ENDPOINT = 'https://wdp.olympus.com.cn:44302/RESTAdapter/NFM703'; |
| | | |
| | | //先款后修 |
| | | NFM112_ENDPOINT = 'http://wdp.olympus.com.cn:8089/RESTAdapter/NFM112'; |
| | | //样本管理 |
| | | NFM115_ENDPOINT = 'https://wdp.olympus.com.cn:44302/RESTAdapter/NFM115'; |
| | | |