GWY
2022-04-06 7560140a14a60e949e6130d98225297e84f0a198
force-app/main/default/classes/RadiationUtil.cls
@@ -2,6 +2,8 @@
    public static Boolean oldOrder = false;
    public static BOolean is_oly = false;
    public static Boolean EscapeOrderTriggerHandler = true;
    /**
     * [updateRadiationTypeQuantity description]更新代理商证照明细,更新奥林巴斯代理商的证照明细
@@ -13,7 +15,7 @@
    public static void updateRadiationTypeQuantity (String Id, String orderFounder, String dealerId, Boolean toloseFlag, String operationType, String operator) {
        String olympusAccountId = oldOrder ? System.label.Olympus_Id : System.label.newOlympus_Id;
        String olympusAccountId =  System.label.Olympus_Id ;
        String orderId = Id;
        //获取合同的辐射类型和数量
@@ -23,7 +25,9 @@
            //查代理商的代理商购买明细
            Map<String, PurchaseDetails__c> dealerModelQuantityMap = GetPurchaseDetailsMap(dealerId);
            //查奥林巴斯的代理商购买明细
            is_oly = true;
            Map<String, PurchaseDetails__c> olympusModelQuantityMap = GetPurchaseDetailsMap(olympusAccountId);
            is_oly = false;
            // 查找 合同提交对应的代理商购买明细
            Map<String, PurchaseDetails__c> dealerResult = new Map<String, PurchaseDetails__c>();
            Map<String, PurchaseDetails__c> olympusResult = new Map<String, PurchaseDetails__c>();
@@ -117,7 +121,9 @@
                    } else {//增加已售产品数量
                        reportMap.putAll(upsertChangedReport(olympusAccountId, radiationType, operationType, orderId, quantity, operator));
                        is_oly = true;
                        olympusModelQuantityMap = insertPurchaseDetail(olympusModelQuantityMap, olympusAccountId, radiationType, radiationTypeQuantityMap);
                        is_oly = false;
                    }
                } else {//减去已售产品数量
                    if (toloseFlag) {
@@ -125,7 +131,9 @@
                        olympusResult.get(radiationType).SoldNumber__c -= quantity;
                    } else {//增加已售产品数量
                        reportMap.putAll(upsertChangedReport(olympusAccountId, radiationType, operationType, orderId, quantity, operator));
                        is_oly = true;
                        olympusModelQuantityMap = insertPurchaseDetail(olympusModelQuantityMap, olympusAccountId, radiationType, radiationTypeQuantityMap);
                        is_oly = false;
                    }
                    
                }
@@ -140,7 +148,9 @@
                if ( olympusResult.size() > 0 && olympusResult != null) {
                    upsert olympusResult.values();
                    is_oly = true;
                    insertReportMap.putAll(insertChangedReport(olympusResult, reportMap));
                    is_oly = false;
                }
            } else {
@@ -151,7 +161,9 @@
                if ( olympusModelQuantityMap.size() > 0 && olympusModelQuantityMap != null) {
                    upsert olympusModelQuantityMap.values();
                    is_oly = true;
                    insertReportMap.putAll(insertChangedReport(olympusModelQuantityMap, reportMap));
                    is_oly = false;
                }
            }
                
@@ -161,7 +173,9 @@
            
            Map<String, Integer> radiationMap =  new Map<String, Integer>();
            String accountDealerErrorMessage = updateCertificationDetails(dealerId, orderFounder, radiationMap, true);
            is_oly = true;
            String olympusDealerErrorMessage = updateCertificationDetails(olympusAccountId, orderFounder, radiationMap, true);
            is_oly = false;
        }
    }
@@ -178,6 +192,7 @@
            String accountId = detail.PurchaseAccount__c;
            //String accountIdafter = accountId.subString(0,15);
            String key = accountId.subString(0, 15) + detail.PurProductModel__c;
            if (reportMap.containsKey(key)) {
                reportMap.get(key).ChangedPurchase__c = detail.Id;
            }
@@ -194,9 +209,11 @@
     * @return              [description]
     */
    public static String updateCertificationDetails( String accountId, String orderFounder, Map<String, Decimal> dataMap, Boolean updateFlag) {
        Map<String, CertificationDetails__c> certificationDetailMap = GetAccountCertificationDetail(accountId);
        Map<String, CertificationDetails__c> temporaryCertificationDetailMap = GetAccountCertificationDetail(accountId);
        Map<String, PurchaseDetails__c> purchaseDetailMap = GetPurchaseDetailsMap(accountId);
        Map<String, CertificationDetails__c> updatecertificationDetailMap = new Map<String, CertificationDetails__c>();
@@ -370,7 +387,19 @@
     */
    public static Map<String, CertificationDetails__c> GetAccountCertificationDetail (String accountId) {
        Map<String, CertificationDetails__c> result = new Map<String, CertificationDetails__c>();
        List<CertificationDetails__c> certificationDetailsList = [ select Id, Name, ProdustionType__c,
        List<CertificationDetails__c> certificationDetailsList = new List<CertificationDetails__c>();
        if (oldOrder && is_oly) {
            certificationDetailsList = [ select Id, Name, ProdustionType__c,
                                    ProductModelNumber__c, Ceiling80__c, Record80__c, Ceiling90__c, Record90__c ,
                                    CertificationDetailAccount__c, CertificationDetailAccountName__c,
                                    LicenseInformation__r.IfQuantityCtrl__c,AccountRecordType__c,Record100__c,
                                    Ceiling100__c
                                    from CertificationDetails__c
                                    where CertificationDetailAccount__c = :accountId
                                        and ActivitieTypes__c = '销售' and IsActive__c = false];
        }else{
            certificationDetailsList = [ select Id, Name, ProdustionType__c,
                                    ProductModelNumber__c, Ceiling80__c, Record80__c, Ceiling90__c, Record90__c , 
                                    CertificationDetailAccount__c, CertificationDetailAccountName__c,
                                    LicenseInformation__r.IfQuantityCtrl__c,AccountRecordType__c,Record100__c,
@@ -378,6 +407,8 @@
                                    from CertificationDetails__c 
                                    where CertificationDetailAccount__c = :accountId  
                                        and ActivitieTypes__c = '销售' and IsActive__c = true];
        }
        for  (CertificationDetails__c detail : certificationDetailsList) {
            result.put(detail.ProdustionType__c, detail);
@@ -407,6 +438,11 @@
        purchaseDetail.PurProductModel__c = productModel;
        purchaseDetail.PurchaseAccount__c = id;
        purchaseDetail.TakeEffectInYear__c = effectiveYear;
        if (oldOrder && is_oly) {
            purchasedetail.company__c = '奥林巴斯';
        }else if(is_oly){
            purchaseDetail.company__c = '仪景通光学科技';
        }
        for (String model:certificationDetailMap.keySet()) {
            if ('Delta和Vanta'.equals(model)) {
@@ -463,10 +499,25 @@
    public static Map<String, PurchaseDetails__c> GetPurchaseDetailsMap( String accountId) {
        String effectiveYear = String.valueOf(Date.today().year());
        Map<String, PurchaseDetails__c> result = new Map<String, PurchaseDetails__c>();
        List<PurchaseDetails__c> purchaseDetailsList = [select Id, Name, RemainingNumber__c, SoldNumber__c,
        List<PurchaseDetails__c> purchaseDetailsList = new List<PurchaseDetails__c>();
        if(is_oly == false){
            purchaseDetailsList = [select Id, Name, RemainingNumber__c, SoldNumber__c,
                                 PurProductModel__c, PurchaseAccount__c
                                 from PurchaseDetails__c
                                 where TakeEffectInYear__c = :effectiveYear and PurchaseAccount__c = :accountId];
        }else{
            if (oldOrder) {
                purchaseDetailsList = [select Id, Name, RemainingNumber__c, SoldNumber__c,
                                 PurProductModel__c, PurchaseAccount__c
                                 from PurchaseDetails__c
                                 where TakeEffectInYear__c = :effectiveYear and PurchaseAccount__c = :accountId and company__c = '奥林巴斯'];
            }else{
                purchaseDetailsList = [select Id, Name, RemainingNumber__c, SoldNumber__c,
                                 PurProductModel__c, PurchaseAccount__c
                                 from PurchaseDetails__c
                                 where TakeEffectInYear__c = :effectiveYear and PurchaseAccount__c = :accountId and company__c = '仪景通光学科技'];
            }
        }
        if (purchaseDetailsList.size() > 0) {
            for (PurchaseDetails__c purchaseDetail : purchaseDetailsList) {
                result.put(purchaseDetail.PurProductModel__c, purchaseDetail);