From 3962c2bb0435484b60a3e408e4738d792e249a53 Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期一, 05 六月 2023 11:09:55 +0800
Subject: [PATCH] LEX CommunityNewCmp

---
 force-app/main/default/classes/LexConsumableAccountController.cls |  422 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 422 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/classes/LexConsumableAccountController.cls b/force-app/main/default/classes/LexConsumableAccountController.cls
new file mode 100644
index 0000000..9925a02
--- /dev/null
+++ b/force-app/main/default/classes/LexConsumableAccountController.cls
@@ -0,0 +1,422 @@
+public without sharing class LexConsumableAccountController {
+    //缁忛攢鍟嗙敤鎴蜂骇鍝佸垎绫伙紙ET銆丒NG锛�
+    public static String agencyProType { get; set; }
+    public static String agencyProTypestr { get; set; }
+    //閫夐」鍗″悕绉�
+    public static String filterName { get; set; }
+    //閫夐」鍗$被鍨�
+    public static String hosptialType { get; set; }
+    public static ApexPages.StandardSetController setCon { get; set; }
+    //鐢婚潰鏄剧ず鏁伴噺
+    public static Integer size { get; set; }
+    public static Integer noOfRecords { get; set; }
+    //鏄剧ず闆嗗悎
+    public static List<Account> pageRecords { get; set; }
+    //缁忛攢鍟嗕俊鎭�
+    private static String accountName { get; set; }
+    private static String accountId { get; set; }
+    //鎺掑簭浣跨敤
+    // public static String sortKey { get; set; }
+    // public static String preSortKey { get; private set; }
+    // public static Boolean sortOrderAsc { get; private set; }
+    // public static String[] sortOrder { get; private set; }
+    // //鎺掑簭浣跨敤
+    // private static String[] orderby = new String[]{ 'Name','State_Master__c','Salesdepartment_HP__c','CreatedDate','Is_Active__c','RecordType.Name','Grade__c','OCM_Category__c','City_Master__c','Town__c','Phone'};
+    //涓婂懆寮�濮嬨�佺粨鏉熸棩鏈�
+    private static Datetime lastweekstart { get; set; }
+    private static Datetime lastweekend { get; set; }
+    // page
+    public static Integer pagesize { get; set; }
+    public static Integer pageToken { get; set; }
+    public static String sortField { get; set; }
+    public static String sortOrder { get; set; }
+    public static Integer totalcount { get; set; }
+
+    //鍒濆鍖�
+    @AuraEnabled
+    public static ResponseBodyLWC init(Integer pageSizeLWC, Integer pageTokenLWC, String fiscalYear) {
+        try {
+            ResponseBodyLWC res = new ResponseBodyLWC();
+            Map<String, object> data = new Map<String, object>();
+            res.entity = data;
+
+            pageSize = pageSizeLWC;
+            pageToken = pageTokenLWC > 2000 ? 2000 : pageTokenLWC;
+
+            User Useracc = [SELECT accountid, UserPro_Type__c FROM user WHERE id = :UserInfo.getUserId()];
+            accountId = [SELECT id, Name FROM account WHERE id = :Useracc.accountid].id;
+            agencyProType = Useracc.UserPro_Type__c;
+            if (String.isBlank(Useracc.UserPro_Type__c)) {
+                agencyProType = 'ET';
+            }
+            agencyProTypestr = '%' + agencyProType + '%';
+            System.debug('accountId = ' + accountId);
+            System.debug('agencyProTypestr = ' + agencyProTypestr);
+            List<Account> allSelectAccount = [
+                SELECT
+                    id,
+                    Name,
+                    State_Master__c,
+                    State_Master__r.Name,
+                    Salesdepartment_HP__c,
+                    CreatedDate,
+                    Is_Active__c,
+                    RecordType.Name,
+                    Grade__c,
+                    OCM_Category__c,
+                    City_Master__c,
+                    City_Master__r.Name,
+                    Town__c,
+                    Phone
+                FROM Account
+                WHERE
+                    id IN (
+                        SELECT Hospital__c
+                        FROM Agency_Hospital_Link__c
+                        WHERE Agency__c = :accountId AND Hosptial_Type__c LIKE :agencyProTypestr
+                    )
+            ];
+            totalCount = allSelectAccount.size();
+
+            List<Account> selectAccList = [
+                SELECT
+                    id,
+                    Name,
+                    State_Master__c,
+                    State_Master__r.Name,
+                    Salesdepartment_HP__c,
+                    CreatedDate,
+                    Is_Active__c,
+                    RecordType.Name,
+                    Grade__c,
+                    OCM_Category__c,
+                    City_Master__c,
+                    City_Master__r.Name,
+                    Town__c,
+                    Phone
+                FROM Account
+                WHERE
+                    id IN (
+                        SELECT Hospital__c
+                        FROM Agency_Hospital_Link__c
+                        WHERE Agency__c = :accountId AND Hosptial_Type__c LIKE :agencyProTypestr
+                    )
+                LIMIT :pageSize
+            ];
+            System.debug('selectAccList = ' + selectAccList);
+            PaginatedAccounts paginatedAccounts = new PaginatedAccounts();
+            paginatedAccounts.nextPageToken = (pageToken + pageSize < totalCount) ? pageToken + pageSize : null;
+            paginatedAccounts.recordStart = pageToken + 1;
+            paginatedAccounts.pageNumber = pageToken / pageSize + 1;
+            Integer recordEnd = pageSize * paginatedAccounts.pageNumber;
+            paginatedAccounts.recordEnd = totalCount >= recordEnd ? recordEnd : totalCount;
+            paginatedAccounts.totalRecords = totalCount;
+
+            //閿�閲忓墠鍗佺殑瀹㈡埛
+            // List<Account> acList = [
+            //     SELECT
+            //         id,
+            //         Name,
+            //         State_Master__c,
+            //         State_Master__r.Name,
+            //         Salesdepartment_HP__c,
+            //         CreatedDate,
+            //         Is_Active__c,
+            //         RecordType.Name,
+            //         Grade__c,
+            //         OCM_Category__c,
+            //         City_Master__c,
+            //         City_Master__r.Name,
+            //         Town__c,
+            //         Phone
+            //     FROM Account
+            //     WHERE State_Master__r.Name != '' AND City_Master__r.Name != '' AND Is_Active__c = '鏈夊姽' AND RecordType.Name = '鐥呴櫌'
+            //     LIMIT 10
+            // ];
+            TopInfo topInfo = new TopInfo();
+
+            Date today = Date.today();
+            Integer lastYear = today.year() - 1;
+            Integer thisYear = today.year();
+            Integer nextYear = today.year() + 1;
+            Date lastDatetime = Date.newInstance(lastYear, 4, 1);
+            Date thisDatetime = Date.newInstance(thisYear, 4, 1);
+            Date thisDatetime2 = Date.newInstance(thisYear, 4, 1);
+            Date nextDatetime = Date.newInstance(nextYear, 4, 1);
+
+            AggregateResult[] arList = null;
+
+            System.debug('fiscalYear = ' + fiscalYear);
+            if (fiscalYear == 'thisYear') {
+                AggregateResult[] saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(thisDatetime, nextDatetime);
+                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 = LexConsumableAccountSOQL.getAccountTotalSales(lastDatetime, thisDatetime2);
+                topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
+                System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
+                arList = LexConsumableAccountSOQL.getAccountBySales(lastDatetime, thisDatetime2);
+            } else {
+                AggregateResult[] saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(lastDatetime, nextDatetime);
+                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')));
+                    topInfo.deList.add(Decimal.valueOf(String.valueOf(ar.get('thisAmount'))));  
+                }
+            }
+
+            System.debug('accountList = ' + accountList);
+            System.debug('topInfo = ' + topInfo);
+
+            List<Account> acList = [
+                SELECT
+                    id,
+                    Name,
+                    State_Master__c,
+                    State_Master__r.Name,
+                    Salesdepartment_HP__c,
+                    CreatedDate,
+                    Is_Active__c,
+                    RecordType.Name,
+                    Grade__c,
+                    OCM_Category__c,
+                    City_Master__c,
+                    City_Master__r.Name,
+                    Town__c,
+                    Phone
+                FROM Account
+                WHERE Name = :accountList
+            ];
+
+            List<Account> acListTemp = new List<Account>();
+
+            for (String s : accountList) {
+                for (Account a : acList) {
+                    if (s == a.Name) {
+                        acListTemp.add(a);
+                    }
+                }
+            }
+
+            topInfo.acList = acListTemp;
+
+            data.put('topInfo', topInfo);
+            data.put('pageRecords', selectAccList);
+            data.put('paginatedAccounts', paginatedAccounts);
+            data.put('accountId', accountId);
+            data.put('agencyProType', agencyProType);
+            data.put('agencyProTypestr', agencyProTypestr);
+            res.status = 'Success';
+            res.code = 200;
+            res.msg = '';
+            return res;
+        } catch (Exception e) {
+            return new ResponseBodyLWC('Error', 500, e.getMessage() + e.getLineNumber(), '');
+        }
+    }
+
+    @AuraEnabled
+    public static ResponseBodyLWC changeFiscalYearView(String fiscalYear) {
+        ResponseBodyLWC res = new ResponseBodyLWC();
+        Map<String, object> data = new Map<String, object>();
+        res.entity = data;
+        try {
+            TopInfo topInfo = new TopInfo();
+
+            Date today = Date.today();
+            Integer lastYear = today.year() - 1;
+            Integer thisYear = today.year();
+            Integer nextYear = today.year() + 1;
+            Date lastDatetime = Date.newInstance(lastYear, 4, 1);
+            Date thisDatetime = Date.newInstance(thisYear, 4, 1);
+            Date thisDatetime2 = Date.newInstance(thisYear, 4, 1);
+            Date nextDatetime = Date.newInstance(nextYear, 4, 1);
+
+            AggregateResult[] arList = null;
+
+            System.debug('fiscalYear = ' + fiscalYear);
+            if (fiscalYear == 'thisYear') {
+                AggregateResult[] saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(thisDatetime, nextDatetime);
+                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 = LexConsumableAccountSOQL.getAccountTotalSales(lastDatetime, thisDatetime2);
+                topInfo.saleAmount = Decimal.valueOf(String.valueOf(saleAmountList[0].get('saleAmount')));
+                System.debug('topInfo.saleAmount = ' + topInfo.saleAmount);
+                arList = LexConsumableAccountSOQL.getAccountBySales(lastDatetime, thisDatetime2);
+            } else {
+                AggregateResult[] saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(lastDatetime, nextDatetime);
+                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')));
+                    topInfo.deList.add(Decimal.valueOf(String.valueOf(ar.get('thisAmount'))));
+                }
+                
+            }
+            System.debug('accountList = ' + accountList);
+            System.debug('topInfo = ' + topInfo);
+            List<Account> acList = [
+                SELECT
+                    id,
+                    Name,
+                    State_Master__c,
+                    State_Master__r.Name,
+                    Salesdepartment_HP__c,
+                    CreatedDate,
+                    Is_Active__c,
+                    RecordType.Name,
+                    Grade__c,
+                    OCM_Category__c,
+                    City_Master__c,
+                    City_Master__r.Name,
+                    Town__c,
+                    Phone
+                FROM Account
+                WHERE Name = :accountList
+            ];
+            List<Account> acListTemp = new List<Account>();
+            for (String s : accountList) {
+                for (Account a : acList) {
+                    if (s == a.Name) {
+                        acListTemp.add(a);
+                    }
+                }
+            }
+            topInfo.acList = acListTemp;
+            data.put('topInfo', topInfo);
+            res.status = 'Success';
+            res.code = 200;
+            res.msg = '';
+            return res;
+        } catch (Exception e) {
+            return new ResponseBodyLWC('Error', 500, e.getMessage() + e.getLineNumber(), '');
+        }
+    }
+
+    @AuraEnabled
+    public static ResponseBodyLWC changelistView(
+        String filterNameLwc,
+        String accountIdLwc,
+        String agencyProTypeLwc,
+        Integer pageSizeLWC,
+        Integer pageTokenLWC,
+        String sortFieldLWC,
+        String sortOrderLWC
+    ) {
+        try {
+            ResponseBodyLWC res = new ResponseBodyLWC();
+            Map<String, object> data = new Map<String, object>();
+            res.entity = data;
+
+            filterName = filterNameLwc;
+            accountId = accountIdLwc;
+            agencyProTypestr = agencyProTypeLwc;
+            pageSize = pageSizeLWC;
+            pageToken = pageTokenLWC > 2000 ? 2000 : pageTokenLWC;
+            sortField = sortFieldLWC;
+            sortOrder = sortOrderLWC;
+
+            String soql = makeSoql(filterName, accountId);
+            System.debug('soql1+++++++ ' + soql);
+            List<Account> allSelectAccount = Database.query(soql);
+
+            totalCount = allSelectAccount.size();
+            if (String.isNotBlank(sortField)) {
+                soql += ' order by ' + sortField + ' ' + sortOrder;
+            }
+            soql += ' limit ' + pagesize + ' offset ' + pageToken;
+            System.debug('soql2+++++++ ' + soql);
+            List<Account> selectAccList = Database.query(soql);
+            System.debug('selectAccList = ' + selectAccList);
+
+            PaginatedAccounts paginatedAccounts = new PaginatedAccounts();
+            paginatedAccounts.nextPageToken = (pageToken + pageSize < totalCount) ? pageToken + pageSize : null;
+            paginatedAccounts.recordStart = pageToken + 1;
+            paginatedAccounts.pageNumber = pageToken / pageSize + 1;
+            Integer recordEnd = pageSize * paginatedAccounts.pageNumber;
+            paginatedAccounts.recordEnd = totalCount >= recordEnd ? recordEnd : totalCount;
+            paginatedAccounts.totalRecords = totalCount;
+
+            data.put('pageRecords', selectAccList);
+            data.put('paginatedAccounts', paginatedAccounts);
+            res.status = 'Success';
+            res.code = 200;
+            res.msg = '';
+            return res;
+        } catch (Exception e) {
+            return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), '');
+        }
+    }
+
+    //sql鏂囦綔鎴�
+    private static String makeSoql(String viewName, String accountId) {
+        Date st = Date.today().addDays(-7).toStartOfWeek();
+        lastweekstart = Datetime.newInstance(st.year(), st.month(), st.day(), 8, 0, 0);
+        lastweekend = lastweekstart.addDays(7);
+        String soql = 'SELECT id,Name,State_Master__c,Salesdepartment_HP__c,CreatedDate,Is_Active__c,RecordType.Name,State_Master__r.Name,City_Master__r.Name';
+        soql += ' ,Grade__c,OCM_Category__c,City_Master__c,Town__c,Phone FROM Account';
+        soql +=
+            ' WHERE id in (SELECT Hospital__c FROM Agency_Hospital_Link__c WHERE Agency__c =:accountId AND Hosptial_Type__c like \'%' +
+            String.escapeSingleQuotes(agencyProTypestr.replaceAll('%', '\\%')) +
+            '%\')';
+        if (viewName == '61. 鍖婚櫌_Hospital鑽夋涓殑鍖婚櫌') {
+            soql += ' AND Is_Active__c = \'' + '鑽夋涓�' + '\'';
+        }
+        if (viewName == '62. 鍖婚櫌_Hospital鐢宠涓殑鍖婚櫌') {
+            soql += ' AND Is_Active__c = \'' + '鐢宠涓�' + '\'';
+        }
+        if (viewName == '63. 鍖婚櫌_Hospital涓婂懆鍒涘缓鐨勫尰闄�') {
+            soql += ' AND Is_Active__c = \'' + '鏈夋晥' + '\'';
+            soql += ' AND CreatedDate >= :lastweekstart ';
+            soql += ' AND CreatedDate < :lastweekend ';
+        }
+        System.debug('soql +++++' + soql);
+        return soql;
+    }
+
+    //鍒嗛〉Bean
+    public class PaginatedAccounts {
+        @AuraEnabled
+        public Integer nextPageToken;
+        @AuraEnabled
+        public Integer pageNumber { get; set; }
+        @AuraEnabled
+        public Integer totalRecords { get; set; }
+        @AuraEnabled
+        public Integer recordStart { get; set; }
+        @AuraEnabled
+        public Integer recordEnd { get; set; }
+    }
+
+    //top10 Account
+    public class TopInfo {
+        @AuraEnabled
+        public Decimal saleAmount { get; set; }
+        @AuraEnabled
+        public List<Account> acList { get; set; }
+        @AuraEnabled
+        public List<Decimal> deList { get; set; }
+
+        public TopInfo() {
+            acList = new List<Account>();
+            deList = new List<Decimal>();
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.1