liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
public class infrastructureProjectRelatedOpController {
    // public static List<String>  sortList = new List<String>{'询价','注残','发货','完毕','失单','取消'}; // WYL     DB202312501399 2024/1/29 
    public static List<String>  sortList = new List<String>{'询价','注残','发货'}; // WYL     DB202312501399 2024/1/29 
    @AuraEnabled
    //根据报价Id检索
    public static  Infrastructure_Project__c selectInfrastructureProjectById(String InfProId){
        List<Infrastructure_Project__c> InfrastructureProject = [ SELECT Id,Name,OCSM_Hospital__c,OCSM_Hospital__r.Name
                  FROM Infrastructure_Project__c Where Id = :InfProId];
        Infrastructure_Project__c  InfProobj = new Infrastructure_Project__c();
        if(InfrastructureProject.size()>0){
            InfProobj = InfrastructureProject[0];
        }
        return InfProobj;
    }
    @AuraEnabled
    //根据报价Id检索
    public static  List<Opportunity> selectoppByAccountId(String OCSMHospital ){
        Map<String,List<Opportunity>> OppMap = new Map<String,List<Opportunity>>();
        List<Opportunity> OppList = [ SELECT Id,Name,StageName__c,Opportunity_No__c,Opportunity_stage__c,Shipping_Date_For_Report__c from Opportunity Where Hospital__c = :OCSMHospital and Infrastructure_Project__c =null and StageName__c != '目标'  order by StageName__c asc,CreatedDate desc];
        for (Opportunity Oppobj : OppList) {
            if(OppMap.containsKey(Oppobj.StageName__c)){
                List<Opportunity> oldopp = OppMap.get(Oppobj.StageName__c);
                oldopp.add(Oppobj);
                OppMap.put(Oppobj.StageName__c,oldopp);
            }else{
                List<Opportunity> newopp = new List<Opportunity>();
                newopp.add(Oppobj);
                OppMap.put(Oppobj.StageName__c,newopp);
            }
        }
        List<Opportunity> sortOppList = new List<Opportunity>();
        for (String sortStr : sortList) {
            if(OppMap.containsKey(sortStr)){
                sortOppList.addAll(OppMap.get(sortStr));
            }
        }
        // WYL     DB202312501399 2024/1/29 start
        Date todate = Date.today();
        Date todate2 = todate.addMonths(-18);
        List<Opportunity> sortOppList2 = new List<Opportunity>();
        for (Opportunity opp : sortOppList) {
            if (opp.StageName__c == '注残' || opp.StageName__c == '发货') {
                if (opp.Shipping_Date_For_Report__c>=todate2 && opp.Shipping_Date_For_Report__c <= todate) {
                    sortOppList2.add(opp);
                }
            }else {
                sortOppList2.add(opp);
            }
            
        }
        return sortOppList2;
         // WYL     DB202312501399 2024/1/29 end
    }
 
    @AuraEnabled
    public static  List<Opportunity> selectoppByOpportunityNoc(String OCSMHospital,String OpportunityNoc){
        System.debug('aa+'+OpportunityNoc);
        Map<String,List<Opportunity>> OppMap = new Map<String,List<Opportunity>>();
        String searchSql = 'Select Id,Name,StageName__c,Opportunity_No__c,Opportunity_stage__c,Shipping_Date_For_Report__c From Opportunity Where Infrastructure_Project__c =null and Hospital__c = \''+OCSMHospital+'\' and StageName__c != \'目标\' ';
        String whereSql = '';
        if(OpportunityNoc != null && OpportunityNoc != ''){
            whereSql += 'and (Opportunity_No__c Like ' + '\'%' + OpportunityNoc + '%\' or Name Like ' + '\'%' + OpportunityNoc + '%\') ';
        }
        whereSql += ' order by StageName__c asc,CreatedDate desc';
        searchSql = searchSql + whereSql;
        System.debug('searchSql+'+searchSql);
        List<Opportunity> OppList = Database.query(searchSql);
        for (Opportunity Oppobj : OppList) {
            if(OppMap.containsKey(Oppobj.StageName__c)){
                List<Opportunity> oldopp = OppMap.get(Oppobj.StageName__c);
                oldopp.add(Oppobj);
                OppMap.put(Oppobj.StageName__c,oldopp);
            }else{
                List<Opportunity> newopp = new List<Opportunity>();
                newopp.add(Oppobj);
                OppMap.put(Oppobj.StageName__c,newopp);
            }
        }
        List<Opportunity> sortOppList = new List<Opportunity>();
        for (String sortStr : sortList) {
            if(OppMap.containsKey(sortStr)){
                sortOppList.addAll(OppMap.get(sortStr));
            }
        }
         // WYL     DB202312501399 2024/1/29 start
         Date todate = Date.today();
        Date todate2 = todate.addMonths(-18);
        List<Opportunity> sortOppList2 = new List<Opportunity>();
        for (Opportunity opp : sortOppList) {
            if (opp.StageName__c == '注残' || opp.StageName__c == '发货') {
                if (opp.Shipping_Date_For_Report__c>=todate2 && opp.Shipping_Date_For_Report__c <= todate) {
                    sortOppList2.add(opp);
                }
            }else {
                sortOppList2.add(opp);
            }
            
        }
        return sortOppList2;
         // WYL     DB202312501399 2024/1/29 end
    }
    @AuraEnabled
    public static  String  saveOppInfrastructureProject(String saveValuec){
        Savepoint sp = Database.setSavepoint();
        try {
            List<Opportunity> oppList = (List<Opportunity>)JSON.deserialize(saveValuec,List<Opportunity>.class);
            StaticParameter.EscapeOppandStaTrigger = true;
            update oppList;
            StaticParameter.EscapeOppandStaTrigger = false;
            return 'success';
        } catch (Exception e) {
            Database.rollback(sp);
            return ''+e;
        }
    }
}