buli
2022-05-13 2f4492ee18f90274582fcc2bb06f5e9bf64136e8
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
public with sharing class calendarUtil {
    //日期中间取日历Map
    public static Map<string,OlympusCalendar__c> getCalendarMap(Date beginDate,Date endDate){
        Map<string,OlympusCalendar__c> calendarMap = new Map<string,OlympusCalendar__c>();
        List<OlympusCalendar__c> calendarList = [select id,Date__c,IsWorkDay__c from OlympusCalendar__c where Date__c >= :beginDate and Date__c <= :endDate];
        for(OlympusCalendar__c cal : calendarList){
            Date datetemp = cal.Date__c;
            calendarMap.put(datetemp.format(),cal);
        }
        return calendarMap;
    }
    //获取两个日期间的工资日
    public static Integer getNumfromCalendarMap (Map<string,OlympusCalendar__c> calendarMap,Date beginDate,Date endDate){
        Integer num = 0;
        List<OlympusCalendar__c> calendarList = new List<OlympusCalendar__c>();
        Set<String> keys = calendarMap.keySet();
        for(String key : keys){
            Date keyDate = Date.valueOf(key.replace('/', '-'));
            if(beginDate<=keyDate && keyDate <= endDate){
                calendarList.add(calendarMap.get(key));
            }
        }
        for(OlympusCalendar__c oly : calendarList){
            if(oly.IsWorkDay__c == 1){
                system.debug(oly.Date__c+'   '+oly.IsWorkDay__c);
                num++;
            }
        }
 
        return num;
    }
    //获取日期num个工作日之后\之前的日期
    public static Date getCorrespondingDate(Map<String,OlympusCalendar__c> calendarMap,Date beginDate,Integer num){
        Integer count = 0;
        Date temp ;
        if(num > 0){
            for(Integer i = 1;;i++){
                temp = beginDate.addDays(i);
                String str = temp.format();
                OlympusCalendar__c oly = calendarMap.get(str);
                if(oly.IsWorkDay__c == 1){
                    count++;
                }
                if(num == count){
                    break;
                }
            }
        }else{
            for(Integer i = -1;;i--){
                temp = beginDate.addDays(i);
                String str = temp.format();
                OlympusCalendar__c oly = calendarMap.get(str);
                if(oly.IsWorkDay__c == 1){
                    count--;
                }
                if(num == count){
                    break;
                }
            }
        }
        return temp;
    }
 
 
    //获取两个日期间的工资日
    public static string getWorkDayNum (String beginStr,String endStr){
 
        Date beginDate = Date.valueOf(beginStr.replace('/', '-'));
        Date endDate = Date.valueOf(endStr.replace('/', '-')); 
 
        Map<String,OlympusCalendar__c> olmap = calendarUtil.getCalendarMap(beginDate.addDays(-1),endDate.addDays(1));
 
        Integer count = calendarUtil.getNumfromCalendarMap(olmap,beginDate,endDate);
 
        return String.valueOf(count);
 
    }
 
    //获取days个工作日之前或之后的日期
    public static String getWorkDay(String beginStr,String days){
 
        Date beginDate = Date.valueOf(beginStr.replace('/', '-'));
        Integer num = Integer.valueOf(days);
        Map<String,OlympusCalendar__c> olmap = new Map<String,OlympusCalendar__c>();
        if(num<0){
            olmap = calendarUtil.getCalendarMap(beginDate.addDays(num-20),beginDate.addDays(1));
        }else{
            olmap = calendarUtil.getCalendarMap(beginDate.addDays(-1),beginDate.addDays(num+20));
        }
 
        Date newDate = calendarUtil.getCorrespondingDate(olmap,beginDate,num);
 
        return String.valueOf(newDate);
    }
 
    // 在自定义标签中获取老的简档ID  calendarUtil.getMemberProfileID
    public static String getMemberProfileID(String memberID){
 
        if(String.isBlank(memberID) || memberID.length()<15) return '0000000000000000';
 
        memberID = memberID.substring(0, 15);
        List<String> allProfile = Profile();
        for(String profile:allProfile){
            if(String.isNotBlank(profile) && profile.contains(':')){
                List<String> profileList = profile.split(':');
                if(profileList.size() > 1 && profileList[1].contains(memberID)){
                    return profileList[0];
                }
            }
        }
        return '0000000000000000';
    }
 
    private static List<String> Profile(){
        List<String> profilList = new List<String>();
        profilList.add(System.label.SSBG_ANI);
        // profilList.add(System.label.SSBG_ANI_after);
        profilList.add(System.label.SSBG_ANI_manager);
        profilList.add(System.label.SSBG_IE);
        profilList.add(System.label.SSBG_IE_Manager_Above);
        // profilList.add(System.label.SSBG_IE_after);
        profilList.add(System.label.SSBG_IE_One);
        profilList.add(System.label.SSBG_IE_manager);
        profilList.add(System.label.SSBG_LS);
        profilList.add(System.label.SSBG_LS_Manager_Above);
        profilList.add(System.label.SSBG_LS_OnlyLoaner);
        profilList.add(System.label.SSBG_LS_notone);
        profilList.add(System.label.SSBG_LS_prototype_manager);
        profilList.add(System.label.SSBG_NDT);
        profilList.add(System.label.SSBG_NDT_Manager_Above);
        profilList.add(System.label.SSBG_NDT_prototype_manager);
        profilList.add(System.label.SSBG_Read_Only);
        profilList.add(System.label.SSBG_Read_Only_OT);
        profilList.add(System.label.SSBG_RVI);
        // profilList.add(System.label.SSBG_RVI_one);
        profilList.add(System.label.SSBG_RVI_after_one);
        profilList.add(System.label.SSBG_RVI_2);
        profilList.add(System.label.SSBG_Scientific_management_headquarters);
        profilList.add(System.label.SSBG_Service_Manager);
        profilList.add(System.label.SSBG_service_department);
        profilList.add(System.label.SSBG_Compliance_department);
        profilList.add(System.label.SSBG_Market_promotion_department);
        profilList.add(System.label.SSBG_Scientific_management_headquarters2);
        profilList.add(System.label.SSBG_Business_management_department);
        profilList.add(System.label.SSBG_Strategic_planning_department);
        profilList.add(System.label.SSBG_Business_management_department2);
        profilList.add(System.label.SSBG_Business_management_department_Have_price);
        profilList.add(System.label.Trial_Customer_Portal_User);
        profilList.add(System.label.system_administrator);
        profilList.add(System.label.system_administrator2);
        profilList.add(System.label.SystemAdmin_GPI_New);
        return profilList;
    }
}