| | |
| | | @RestResource(urlMapping='/CPL003/*') |
| | | global with sharing class CPL003Rest { |
| | | |
| | | global class GeDatas { |
| | | webservice NFMUtil.Monitoring Monitoring; |
| | | webservice CPL003Rest.GeData[] Inventory; |
| | | webService NFMUtil.Monitoring Monitoring; |
| | | webService CPL003Rest.GeData[] Inventory; |
| | | } |
| | | |
| | | global class GeData { |
| | | webservice String MaterialNumber; //产品编码(产品代码) |
| | | webservice String ItemQuantity; //OpenPO和库存的总数量 |
| | | webService String MaterialNumber; //产品编码(产品代码) |
| | | webService String ItemQuantity; //OpenPO和库存的总数量 |
| | | |
| | | webservice String Area; //区域(待定) |
| | | webService String Area; //区域(待定) |
| | | //webservice String other1; |
| | | //webservice String other2; |
| | | //webservice String other3; |
| | | } |
| | | |
| | | @HttpPost |
| | | @HttpPost |
| | | global static void execute() { |
| | | // 取得接口传输内容 |
| | | // 取得接口传输内容 |
| | | String strData = RestContext.request.requestBody.toString(); |
| | | GeDatas ges = (GeDatas) JSON.deserializeStrict(strData, GeDatas.class); |
| | | |
| | | if (ges == null ) { |
| | | if (ges == null) { |
| | | return; |
| | | } |
| | | |
| | |
| | | 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]; |
| | | MDMITMWebService.isRunning = true; |
| | | 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 |
| | | ]; |
| | | //MDMITMWebService.isRunning = true; //Commented By Li Jun 20230428 |
| | | String logstr = rowData.MessageGroupNumber__c + ' start\n'; |
| | | BatchIF_Log__c iflog = new BatchIF_Log__c(); |
| | | iflog.Type__c = 'CPL003'; |
| | |
| | | String rowDataStr = NFMUtil.getRowDataStr(rowData); |
| | | //rowDataStr = XMLTools.xml2json(rowDataStr); |
| | | List<GeData> itemMasterList = (List<GeData>) JSON.deserialize(rowDataStr, List<GeData>.class); |
| | | |
| | | |
| | | if (itemMasterList == null || itemMasterList.size() == 0) { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | Savepoint sp = Database.setSavepoint(); |
| | | |
| | | try{ |
| | | try { |
| | | List<String> materialNumberList = new List<String>(); |
| | | |
| | | for (GeData GeData : itemMasterList) { |
| | | if (String.isBlank(GeData.MaterialNumber)) continue; |
| | | if (String.isBlank(GeData.ItemQuantity)) continue; |
| | | if (String.isBlank(GeData.MaterialNumber)) |
| | | continue; |
| | | if (String.isBlank(GeData.ItemQuantity)) |
| | | continue; |
| | | materialNumberList.add(GeData.MaterialNumber); |
| | | } |
| | | |
| | | List<Product2> product2List = [select Id, ProductCode, StorageStatusNo__c |
| | | from Product2 |
| | | where ProductCode in :materialNumberList ]; |
| | | |
| | | Map<String,Product2> product2Map = new Map<String,Product2>(); |
| | | List<Product2> product2List = [ |
| | | SELECT Id, ProductCode, StorageStatusNo__c |
| | | FROM Product2 |
| | | WHERE ProductCode IN :materialNumberList |
| | | ]; |
| | | |
| | | Map<String, Product2> product2Map = new Map<String, Product2>(); |
| | | for (Product2 product2 : product2List) { |
| | | product2Map.put(product2.ProductCode, product2); |
| | | } |
| | | |
| | | List<Product2> upsertProList = new List<Product2>(); |
| | | Map<String,Product2> prdUpdateMap = new Map<String, Product2>(); |
| | | Map<String, Product2> prdUpdateMap = new Map<String, Product2>(); |
| | | |
| | | for (GeData GeData : itemMasterList) { |
| | | |
| | | if (String.isBlank(GeData.MaterialNumber)) { |
| | | iflog.ErrorLog__c += 'MaterialNumber is required.\n'; |
| | | continue; |
| | |
| | | Product2 product = product2Map.get(GeData.MaterialNumber); |
| | | product.StorageStatusNo__c = Double.valueOf(GeData.ItemQuantity); |
| | | upsertProList.add(product); |
| | | |
| | | } else { |
| | | iflog.ErrorLog__c += 'This MaterialNumber [ ' + GeData.MaterialNumber + ' ] is not Exist.\n'; |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | if(upsertProList.size() > 0) upsert upsertProList; |
| | | if (upsertProList.size() > 0) |
| | | upsert upsertProList; |
| | | |
| | | logstr += '\nend'; |
| | | rowData.retry_cnt__c=0; |
| | | } catch(Exception ex) { |
| | | rowData.retry_cnt__c = 0; |
| | | } catch (Exception ex) { |
| | | // エラーが発生した場合 |
| | | Database.rollback(sp); |
| | | 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){ |
| | | 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+'错误次数已经超过自动收信设定的最大次数,请手动收信'; |
| | | if (rowData.retry_cnt__c >= batch_retry_max_cnt) { |
| | | rowData.ErrorLog__c = |
| | | ex.getMessage() + |
| | | '\n' + |
| | | ex.getStackTraceString() + |
| | | '\n' + |
| | | rowData.ErrorLog__c + |
| | | '错误次数已经超过自动收信设定的最大次数,请手动收信'; |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | update iflog; |
| | | } |
| | | } |
| | | } |