高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
public with sharing class HomeBulletinBoardController {
    public List<HBBInfo> hbbInfoList {get; private set;}
    public void init() {
        hbbInfoList = new List<HBBInfo>();
        
        // TODO 公開開始日<=today && 公開終了日>today
        List<HBBInfo> tmpList = new List<HBBInfo>();
        List<Product_Documentation__c> pdList = [select Id, Material_open_day__c, Material_category__c, Product_document_name__c
                                                 from Product_Documentation__c 
                                                 where Material_status__c = '公开中'
                                                 order by Material_open_day__c desc limit 20];
        for (Product_Documentation__c pd : pdList) {
            tmpList.add(new HBBInfo(pd));
        }
        
        List<Bulletin_Board__c> bbList = [select Id, Board_open_day__c, Board_category1__c, Name
                                          from Bulletin_Board__c
                                          where Board_status__c = '公开中'
                                          order by Board_open_day__c desc limit 20];
        for (Bulletin_Board__c bb : bbList) {
            tmpList.add(new HBBInfo(bb));
        }
        
        List<Solution> faqList = [select Id, FAQ_disclosed_day__c, Question_category__c, SolutionName
                                          from Solution
                                          where Status = 'レビュー済み'
                                          order by FAQ_disclosed_day__c desc limit 20];
        for (Solution faq : faqList) {
            tmpList.add(new HBBInfo(faq));
        }
        
        List<Campaign> camList = [select Id, StartDate, RecordType.Name, Name
                                          from Campaign
                                          where (Status = '公开中' or Status = '已结束' or Status = '已提交报告')
                                          order by StartDate desc limit 20];
        for (Campaign cam : camList) {
            tmpList.add(new HBBInfo(cam));
        }        
        
        tmpList.sort();
        // 先頭の40件だす、後ろから抽出
        Integer cnt = 0;
        for (Integer i = tmpList.size() - 1; i >= 0; i--) {
            hbbInfoList.add(tmpList[i]);
            cnt++;
            if (cnt == 40) {
                break;
            }
        }
    }
    public class HBBInfo implements Comparable {
        public Id linkId {get; private set;}
        public Date openday {get; private set;}
        public String daiBunrui {get; private set;}
        public String bunrui {get; private set;}
        public String subject {get; private set;}
        
        public HBBInfo(Product_Documentation__c pd) {
            linkId = pd.Id;
            openday = pd.Material_open_day__c;
            daiBunrui = Schema.SObjectType.Product_Documentation__c.Label;
            bunrui = pd.Material_category__c;
            subject = pd.Product_document_name__c;
        }
        
        public HBBInfo(Bulletin_Board__c bb) {
            linkId = bb.Id;
            openday = bb.Board_open_day__c;
            daiBunrui = Schema.SObjectType.Bulletin_Board__c.Label;
            bunrui = bb.Board_category1__c;
            subject = bb.Name;
        }
 
        public HBBInfo(Solution faq) {
            linkId = faq.Id;
            openday = faq.FAQ_disclosed_day__c;
            daiBunrui = Schema.SObjectType.Solution.Label;
            bunrui = faq.Question_category__c;
            subject = faq.SolutionName;
        }
        
        public HBBInfo(Campaign cam) {
            linkId = cam.Id;
            openday = cam.StartDate;
            daiBunrui = Schema.SObjectType.Campaign.Label;
            bunrui = cam.RecordType.Name;
            subject = cam.Name;
        }
        
        // openday順
        public Integer compareTo(Object compareTo) {
            HBBInfo bbInfo = (HBBInfo)compareTo;
            if (openday == bbInfo.openday) return 0;
            if (openday > bbInfo.openday) return 1;
            return -1;
        }
    }
}