binxie
2023-06-26 00e147ec892cb1e89d0698787a8c60da1014cdb7
force-app/main/default/classes/LexConsumableAccountController.cls
@@ -148,70 +148,50 @@
            System.debug('fiscalYear = ' + fiscalYear);
            if (fiscalYear == 'thisYear') {
                AggregateResult[] saleAmountList = [
                    SELECT sum(Sale_amount__c) saleAmount
                    FROM Consumable_Orderdetails__c
                    WHERE CreatedDate >= :thisDatetime AND CreatedDate < :nextDatetime
                ];
                AggregateResult[] saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(thisDatetime, nextDatetime);
                topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
                System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
                arList = [
                    SELECT count(id), Consumable_order__r.Order_ForHospital__r.name hospitalName, sum(Sale_amount__c) thisAmount
                    FROM Consumable_Orderdetails__c
                    WHERE
                        CreatedDate >= :thisDatetime
                        AND CreatedDate < :nextDatetime
                        AND Consumable_order__r.Order_ForHospital__r.name != ''
                    GROUP BY Consumable_order__r.Order_ForHospital__r.Name
                    ORDER BY sum(Sale_amount__c) DESC
                    LIMIT 10
                ];
                arList = LexConsumableAccountSOQL.getAccountBySales(thisDatetime, nextDatetime);
            } else if (fiscalYear == 'lastYear') {
                AggregateResult[] saleAmountList = [
                    SELECT sum(Sale_amount__c) saleAmount
                    FROM Consumable_Orderdetails__c
                    WHERE CreatedDate >= :lastDatetime AND CreatedDate < :thisDatetime2
                ];
                AggregateResult[] saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(lastDatetime, thisDatetime2);
                topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
                System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
                arList = [
                    SELECT count(id), Consumable_order__r.Order_ForHospital__r.name hospitalName, sum(Sale_amount__c) thisAmount
                    FROM Consumable_Orderdetails__c
                    WHERE
                        CreatedDate >= :lastDatetime
                        AND CreatedDate < :thisDatetime2
                        AND Consumable_order__r.Order_ForHospital__r.name != ''
                    GROUP BY Consumable_order__r.Order_ForHospital__r.Name
                    ORDER BY sum(Sale_amount__c) DESC
                    LIMIT 10
                ];
                arList = LexConsumableAccountSOQL.getAccountBySales(lastDatetime, thisDatetime2);
            } else {
                AggregateResult[] saleAmountList = [
                    SELECT sum(Sale_amount__c) saleAmount
                    FROM Consumable_Orderdetails__c
                    WHERE CreatedDate >= :lastDatetime AND CreatedDate < :nextDatetime
                ];
                AggregateResult[] saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(lastDatetime, nextDatetime);
                topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
                System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
                arList = [
                    SELECT count(id), Consumable_order__r.Order_ForHospital__r.name hospitalName, sum(Sale_amount__c) thisAmount
                    FROM Consumable_Orderdetails__c
                    WHERE
                        CreatedDate >= :lastDatetime
                        AND CreatedDate < :nextDatetime
                        AND Consumable_order__r.Order_ForHospital__r.name != ''
                    GROUP BY Consumable_order__r.Order_ForHospital__r.Name
                    ORDER BY sum(Sale_amount__c) DESC
                    LIMIT 10
                ];
                arList = LexConsumableAccountSOQL.getAccountBySales(lastDatetime, nextDatetime);
            }
            // Map<String,Decimal> mapTemp = new Map<String,Decimal>();
            // for (AggregateResult ar : arList) {
            //     if(!mapTemp.get(String.valueOf(ar.get('hospitalName')))){
            //         mapTemp.put(String.valueOf(ar.get('hospitalName'),Decimal.valueOf(String.valueOf(ar.get('thisAmount')))));
            //     }else {
            //         Decimal decimal = mapTemp.get(String.valueOf(ar.get('hospitalName')));
            //         decimal += Decimal.valueOf(String.valueOf(ar.get('thisAmount')));
            //         mapTemp.put(String.valueOf(ar.get('hospitalName'),decimal));
            //     }
            // }
            // System.debug('mapTemp = ' + mapTemp);
            // //排序Decimal从大到小
            // List<Decimal> decimalList = new List<Decimal>(mapTemp.values());
            // decimalList.sort((a, b) => b.compareTo(a));
            // Map<String, Decimal> sortedMap = new Map<String, Decimal>();
            // for (String key : mapTemp.keySet()) {
            //     sortedMap.put(key, mapTemp.get(key));
            // }
            // System.debug('Sorted Map: ' + sortedMap);
            //查询客户信息(名称,省,县)
            System.debug('arList = ' + arList);
            List<String> accountList = new List<String>();
            for (AggregateResult ar : arList) {
                System.debug('thisAmount = ' + String.valueOf(ar.get('thisAmount')));
                if(String.valueOf(ar.get('thisAmount')) != '0.0'){
                    accountList.add(String.valueOf(ar.get('hospitalName')));
                    accountList.add(String.valueOf(ar.get('Order_ForHospital__c')));
                    topInfo.deList.add(Decimal.valueOf(String.valueOf(ar.get('thisAmount'))));  
                }
            }
@@ -236,14 +216,14 @@
                    Town__c,
                    Phone
                FROM Account
                WHERE Name = :accountList
                WHERE Id = :accountList
            ];
            List<Account> acListTemp = new List<Account>();
            for (String s : accountList) {
                for (Account a : acList) {
                    if (s == a.Name) {
                    if (s == a.id) {
                        acListTemp.add(a);
                    }
                }
@@ -286,73 +266,39 @@
            AggregateResult[] arList = null;
            System.debug('fiscalYear = ' + fiscalYear);
            System.debug('thisYear = ' + thisYear);
            System.debug('lastYear = ' + lastYear);
            if (fiscalYear == 'thisYear') {
                AggregateResult[] saleAmountList = [
                    SELECT sum(Sale_amount__c) saleAmount
                    FROM Consumable_Orderdetails__c
                    WHERE CreatedDate >= :thisDatetime AND CreatedDate < :nextDatetime
                ];
                topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
                System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
                arList = [
                    SELECT count(id), Consumable_order__r.Order_ForHospital__r.name hospitalName, sum(Sale_amount__c) thisAmount
                    FROM Consumable_Orderdetails__c
                    WHERE
                        CreatedDate >= :thisDatetime
                        AND CreatedDate < :nextDatetime
                        AND Consumable_order__r.Order_ForHospital__r.name != ''
                    GROUP BY Consumable_order__r.Order_ForHospital__r.Name
                    ORDER BY sum(Sale_amount__c) DESC
                    LIMIT 10
                ];
                AggregateResult[] saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(thisDatetime, nextDatetime);
                if (saleAmountList[0].get('saleAmount') != null) {
                    topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
                    System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
                }
                arList = LexConsumableAccountSOQL.getAccountBySales(thisDatetime, nextDatetime);
            } else if (fiscalYear == 'lastYear') {
                AggregateResult[] saleAmountList = [
                    SELECT sum(Sale_amount__c) saleAmount
                    FROM Consumable_Orderdetails__c
                    WHERE CreatedDate >= :lastDatetime AND CreatedDate < :thisDatetime2
                ];
                topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
                System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
                arList = [
                    SELECT count(id), Consumable_order__r.Order_ForHospital__r.name hospitalName, sum(Sale_amount__c) thisAmount
                    FROM Consumable_Orderdetails__c
                    WHERE
                        CreatedDate >= :lastDatetime
                        AND CreatedDate < :thisDatetime2
                        AND Consumable_order__r.Order_ForHospital__r.name != ''
                    GROUP BY Consumable_order__r.Order_ForHospital__r.Name
                    ORDER BY sum(Sale_amount__c) DESC
                    LIMIT 10
                ];
                AggregateResult[] saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(lastDatetime, thisDatetime2);
                if (saleAmountList[0].get('saleAmount') != null) {
                    topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
                    System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
                }
                arList = LexConsumableAccountSOQL.getAccountBySales(lastDatetime, thisDatetime2);
            } else {
                AggregateResult[] saleAmountList = [
                    SELECT sum(Sale_amount__c) saleAmount
                    FROM Consumable_Orderdetails__c
                    WHERE CreatedDate >= :lastDatetime AND CreatedDate < :nextDatetime
                ];
                topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
                System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
                arList = [
                    SELECT count(id), Consumable_order__r.Order_ForHospital__r.name hospitalName, sum(Sale_amount__c) thisAmount
                    FROM Consumable_Orderdetails__c
                    WHERE
                        CreatedDate >= :lastDatetime
                        AND CreatedDate < :nextDatetime
                        AND Consumable_order__r.Order_ForHospital__r.name != ''
                    GROUP BY Consumable_order__r.Order_ForHospital__r.Name
                    ORDER BY sum(Sale_amount__c) DESC
                    LIMIT 10
                ];
                AggregateResult[] saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(lastDatetime, nextDatetime);
                if (saleAmountList[0].get('saleAmount') != null) {
                    topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
                    System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
                }
                arList = LexConsumableAccountSOQL.getAccountBySales(lastDatetime, nextDatetime);
            }
            //查询客户信息(名称,省,县)
            List<String> accountList = new List<String>();
            for (AggregateResult ar : arList) {
                System.debug('thisAmount = ' + String.valueOf(ar.get('thisAmount')));
                if(String.valueOf(ar.get('thisAmount')) != '0.0'){
                    accountList.add(String.valueOf(ar.get('hospitalName')));
                if (String.valueOf(ar.get('thisAmount')) != '0.0') {
                    accountList.add(String.valueOf(ar.get('Order_ForHospital__c')));
                    topInfo.deList.add(Decimal.valueOf(String.valueOf(ar.get('thisAmount'))));
                }
            }
            System.debug('accountList = ' + accountList);
            System.debug('topInfo = ' + topInfo);
@@ -373,12 +319,12 @@
                    Town__c,
                    Phone
                FROM Account
                WHERE Name = :accountList
                WHERE Id = :accountList
            ];
            List<Account> acListTemp = new List<Account>();
            for (String s : accountList) {
                for (Account a : acList) {
                    if (s == a.Name) {
                    if (s == a.id) {
                        acListTemp.add(a);
                    }
                }