| | |
| | | |
| | | //初始化 |
| | | @AuraEnabled |
| | | public static ResponseBodyLWC init(Integer pageSizeLWC, Integer pageTokenLWC) { |
| | | public static ResponseBodyLWC init(Integer pageSizeLWC, Integer pageTokenLWC, String fiscalYear) { |
| | | try { |
| | | ResponseBodyLWC res = new ResponseBodyLWC(); |
| | | Map<String, object> data = new Map<String, object>(); |
| | |
| | | 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 = [ |
| | | 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 |
| | | ]; |
| | | } 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 |
| | | ]; |
| | | } 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 |
| | | ]; |
| | | } |
| | | |
| | | //查询客户信息(名称,省,县) |
| | | 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, |
| | |
| | | Town__c, |
| | | Phone |
| | | FROM Account |
| | | WHERE State_Master__r.Name != '' AND City_Master__r.Name != '' AND Is_Active__c = '有効' AND RecordType.Name = '病院' |
| | | LIMIT 10 |
| | | WHERE Name = :accountList |
| | | ]; |
| | | data.put('acList', acList); |
| | | |
| | | 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); |
| | |
| | | res.msg = ''; |
| | | return res; |
| | | } catch (Exception e) { |
| | | return new ResponseBodyLWC('Error', 500, e.getMessage(), ''); |
| | | 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 = [ |
| | | 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 |
| | | ]; |
| | | } 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 |
| | | ]; |
| | | } 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 |
| | | ]; |
| | | } |
| | | //查询客户信息(名称,省,县) |
| | | 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 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>(); |
| | | } |
| | | } |
| | | } |