public with sharing class lexConsumApplyController {

    @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new InitData();
        try {
            List<Consum_Apply__c> caList = [SELECT Id, Campaign__c, Campaign__r.Status, Wei_Assigned_Cnt__c, Status__c,
                                Assigned_Not_Shipment__c,Bollow_Date__c,Yi_loaner_arranged__c, AccDealerBlacklist__c, AccDealerBlacklist2__c    //20240121 sx 贸易合规二期add
                                FROM Consum_Apply__c WHERE Id = :recordId];
            //20240125 sx 贸易合规二期 add start                    
            List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [select id,name,Asset__c,Asset__r.Product2.ProTradeComplianceStatus__c,
                                                                    Asset__r.Account.TradeComplianceStatus__c  
                                                                    from Consum_Apply_Equipment_Set_Detail__c where Consum_Apply__c = :recordId and Asset__c  != null];
            //20240125 sx 贸易合规二期 add start
            if(caList.size()>0){
                Consum_Apply__c ca = caList[0];
                if(ca.Campaign__c != null){
                    res.campaignId = ca.Campaign__c;
                }
                //20240125 sx 贸易合规二期 add start
                List<String> emailEasdList = new List<String>();	//20240206 贸易合规二期邮件 add
                if (caesdList.size()>0) {
                    for (Consum_Apply_Equipment_Set_Detail__c caesd : caesdList) {
                        //20240206修改  应该用申请单医院判断是否是警示名单
                        if (ca.AccDealerBlacklist2__c == '5' && caesd.Asset__r.Product2.ProTradeComplianceStatus__c == '0') {
                            emailEasdList.add(caesd.Id);
                            res.hgerqi = 'true';
                        }
                    }
                }
                //20240206 贸易合规二期邮件 add start
                if(emailEasdList.size() > 0){
                    SendEmailUtil.tradeConsumTempleSend(recordId, '出库指示', null, emailEasdList);
                }
                //20240206 贸易合规二期邮件 end
                //20240125 sx 贸易合规二期 add end
                res.weiAssignedCnt = Integer.valueOf(ca.Wei_Assigned_Cnt__c);
                res.consumApplyStatus = ca.Status__c;
                res.campaignStatus = ca.Campaign__r.Status;
                res.assignedNotShipment = Integer.valueOf(ca.Assigned_Not_Shipment__c);
                res.bollowDate = ca.Bollow_Date__c;
                res.yiLoanerArranged = Integer.valueOf(ca.Yi_loaner_arranged__c);
                res.accDealerBlacklist = ca.AccDealerBlacklist__c;
                res.accDealerBlacklist2 = ca.AccDealerBlacklist2__c;   //20240121 sx 贸易合规二期add 
            }
        }
        catch (Exception e) {
            System.debug('********lexConsumApplyController*****'+e.getMessage());
        }
        return res;
    }

    @AuraEnabled
    public static Integer getLength1(String recordId){
        //AND Shippment_loaner_time__c != null
        List<Consum_Apply_Equipment_Set__c> caeList = [SELECT Id from Consum_Apply_Equipment_Set__c WHERE Consum_Apply__c =:recordId AND RAES_Status__c != '已分配' AND RAES_Status__c != '取消分配'];
        return caeList.size();
    }

    @AuraEnabled
    public static Integer getLength2(String recordId){
        List<Consum_Apply_Equipment_Set__c> caeList = [SELECT Id from Consum_Apply_Equipment_Set__c WHERE Consum_Apply__c =:recordId AND RAES_Status__c != '已分配' AND RAES_Status__c != '取消分配'];
        return caeList.size();
    }

    @AuraEnabled
    public static Consum_Apply_Equipment_Set__c getSet(String setId){
        Consum_Apply_Equipment_Set__c cae = [select Id, Zan_Ding_Fen_Pei_Shu__c from Consum_Apply_Equipment_Set__c where Id= :setId];
        return cae;
    }

    public class InitData{
        @AuraEnabled
        public String campaignId;       //学会Id
        @AuraEnabled
        public String campaignStatus;   //学会状态
        @AuraEnabled
        public Integer weiAssignedCnt;      //未分配件数
        @AuraEnabled
        public String consumApplyStatus;    //状态
        @AuraEnabled
        public Integer assignedNotShipment;      //已分配未出库指示
        @AuraEnabled
        public Date bollowDate;       //备品中心出库日
        @AuraEnabled
        public Integer yiLoanerArranged;    //已出库件数
        @AuraEnabled
        public String accDealerBlacklist;
        @AuraEnabled
        public String hgerqi;
        @AuraEnabled
        public String accDealerBlacklist2;  //20240121 sx 贸易合规二期add
    }
}