高章伟
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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
public class FixtureRemindController {
    public Map<String, Integer> eastMap {set;get;} // 华东
    public Map<String, Integer> eastConsumMap {set;get;} // 华东耗材
    public Map<String, Integer> southMap {set;get;} // 南方
    public Map<String, Integer> northMap {set;get;} // 北方
    public Map<String, Integer> totalMap {set;get;} // 合计
    public Boolean hasEastMap {set;get;} // 华东
    public Boolean hasEastConsumMap {set;get;} // 华东耗材
    public Boolean hasSouthMap {set;get;} // 南方
    public Boolean hasNorthMap {set;get;} // 北方
    public Boolean hasTotalMap {set;get;} // 合计
    public Boolean hasAuthority {set;get;}
 
    public FixtureRemindUtil frUtil{get;set;}
    public FixtureRemindSnapshot__c snap{get;set;}
 
    public FixtureRemindController(){
        this.snap = new FixtureRemindSnapshot__c();
        snap.Date__c = System.today();
        User currentUser = [SELECT UserRole.Name, ProfileId FROM User WHERE Id=: UserInfo.getUserId()];
        // User currentUser = [SELECT UserRole.Name, ProfileId FROM User WHERE Id= '00510000001OOJx'];
        this.hasAuthority     = false;
        this.hasNorthMap      = false;
        this.hasSouthMap      = false;
        this.hasEastMap       = false;
        this.hasTotalMap      = false;
        this.hasEastConsumMap = false;
        //20210519 you WLIG-C2J9AA  || currentUser.UserRole.Name == '备品运营部'
        if (System.Label.ProfileId_EquCenAdmin.contains(currentUser.ProfileId) || currentUser.UserRole.Name == '备品运营部'){
            this.hasAuthority     = true;
            this.hasNorthMap      = true;
            this.hasSouthMap      = true;
            this.hasEastMap       = true;
            this.hasTotalMap      = true;
            this.hasEastConsumMap = true;
        }
        else if(currentUser.UserRole.Name == '备品中心北方管理成员') {
            this.hasAuthority     = true;
            this.hasNorthMap = true;
        }
        else if(currentUser.UserRole.Name == '备品中心南方管理成员') {
            this.hasAuthority     = true;
            this.hasSouthMap      = true;
        }
        else if(currentUser.UserRole.Name == '备品中心华东管理成员') {
            this.hasAuthority     = true;
            this.hasEastMap       = true;
            this.hasEastConsumMap = true;
        }
        this.frUtil = new FixtureRemindUtil();
        this.eastMap = this.frUtil.eastMap;
        this.eastConsumMap = this.frUtil.eastConsumMap;
        this.southMap = this.frUtil.southMap;
        this.northMap = this.frUtil.northMap;
        this.totalMap = this.frUtil.totalMap;
    }
    public void init() {
        if(!hasAuthority){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '您所在的Role无权查看数量'));
            return;
        }
        this.frUtil.init();
    }
    public void refreshTable(){
        if(snap.Time__c == null){
            this.frUtil.init();
            return;
        }
        else if(snap.Date__c != null) {
            this.frUtil.resetAllMaps();
            List<FixtureRemindSnapshot__c> frsList = [
 
                SELECT Id
                     , Region__c
                     , Date__c
                     , Time__c
                     , Consum_Dai_Chu_Ku_Zhi_Shi_Cnt__c
                     , Consum_Dai_Fa_Huo_Cnt__c
                     , Consum_Dai_Fen_Pei_Cnt__c
                     , Consum_Dai_Que_Ren_Shi_Yong_Biao_Cnt__c
                     , Consum_Dai_Shou_Huo_Cnt__c
                     , Consum_Dao_Huo_NG_Dai_Que_Ren_Cnt__c
                     , Dai_Bao_Xiu_Cnt__c
                     , Dai_CDS_Cnt__c
                     , Dai_Chu_Ku_Qian_Jian_Ce_Cnt__c
                     , Dai_Chu_Ku_Zhi_Shi_Cnt__c
                     , Dai_Fa_Huo_Cnt__c
                     , Dai_Fen_Pei_Cnt__c
                     , Dai_Hui_Shou_Hou_Jian_Ce_Cnt__c
                     , Dai_Qian_Pin_Que_Ren_Cnt__c
                     , Dai_Que_Ren_Qian_Shou_Cnt__c
                     , Dai_Shang_Jia_Cnt__c
                     , Dai_Xia_Jia_Cnt__c
                     , Pai_Dui_Zhong_Cnt__c
                     , Qian_Pin_Zhong_Cnt__c
                     , Zan_Ding_Fen_Pei_Cnt__c
                FROM FixtureRemindSnapshot__c
                WHERE Date__c = : snap.Date__c
                AND Time__c = : snap.Time__c
                //add by rentx 20210722 WLIG-C4VDUX
                AND Rental_ApplyRecordtype__c != '办事处' 
                //add by rentx 20210722 WLIG-C4VDUX
                
            ];
 
            Boolean northLoaded = false;
            Boolean southLoaded = false;
            Boolean eastLoaded = false;
            for(FixtureRemindSnapshot__c frs:frsList){
                switch on frs.Region__c{
                    when '北方' {
                        loadMap(this.northMap, frs);
                        northLoaded = true;
                    }
                    when '南方' {
                        loadMap(this.southMap, frs);
                        southLoaded = true;
                    }
                    when '华东' {
                        this.eastConsumMap.put('待分配件数', valueOf(frs.Consum_Dai_Fen_Pei_Cnt__c));
                        this.eastConsumMap.put('待出库指示件数', valueOf(frs.Consum_Dai_Chu_Ku_Zhi_Shi_Cnt__c));
                        this.eastConsumMap.put('待发货件数', valueOf(frs.Consum_Dai_Fa_Huo_Cnt__c));
                        this.eastConsumMap.put('到货NG待确认数量',valueOf(frs.Consum_Dao_Huo_NG_Dai_Que_Ren_Cnt__c));
                        this.eastConsumMap.put('待确认试用表数量', valueOf(frs.Consum_Dai_Que_Ren_Shi_Yong_Biao_Cnt__c));
                        this.eastConsumMap.put('待收货件数', valueOf(frs.Consum_Dai_Shou_Huo_Cnt__c));
                        loadMap(this.eastMap, frs);
                        eastLoaded = true;
                    }
                }
            }
            String regions = '';
            if(this.hasEastMap && !eastLoaded){
                regions +=' 华东 ';
            }
            if(this.hasNorthMap && !northLoaded){
                regions +=' 北方 ';
            }
            if(this.hasSouthMap && !southLoaded){
                regions +=' 南方 ';
            }
            if(String.isNotBlank(regions)){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '该时间' + regions + '没有快照'));
            }
 
            for(String key : this.totalMap.keySet()){
                Integer total = this.eastMap.get(key) + this.northMap.get(key) + this.southMap.get(key);
                this.totalMap.put(key, total);
            }
        }
    }
    private void loadMap(Map<String, Integer> fixtureMap, FixtureRemindSnapshot__c frs){
        fixtureMap.put('待分配件数', valueOf(frs.Dai_Fen_Pei_Cnt__c));
        fixtureMap.put('暂定分配件数', valueOf(frs.Zan_Ding_Fen_Pei_Cnt__c));
        fixtureMap.put('排队中件数', valueOf(frs.Pai_Dui_Zhong_Cnt__c));
        fixtureMap.put('待出库指示件数', valueOf(frs.Dai_Chu_Ku_Zhi_Shi_Cnt__c));
        fixtureMap.put('待下架件数', valueOf(frs.Dai_Xia_Jia_Cnt__c));
        fixtureMap.put('待出库前检测件数', valueOf(frs.Dai_Chu_Ku_Qian_Jian_Ce_Cnt__c));
        fixtureMap.put('待发货件数', valueOf(frs.Dai_Fa_Huo_Cnt__c));
        fixtureMap.put('待确认签收单数', valueOf(frs.Dai_Que_Ren_Qian_Shou_Cnt__c));
        fixtureMap.put('待欠品确认件数', valueOf(frs.Dai_Qian_Pin_Que_Ren_Cnt__c));
        fixtureMap.put('待CDS件数', valueOf(frs.Dai_CDS_Cnt__c));
        fixtureMap.put('待回收后检测件数', valueOf(frs.Dai_Hui_Shou_Hou_Jian_Ce_Cnt__c));
        fixtureMap.put('待上架件数', valueOf(frs.Dai_Shang_Jia_Cnt__c));
        fixtureMap.put('欠品中件数', valueOf(frs.Qian_Pin_Zhong_Cnt__c));
        fixtureMap.put('待报修件数', valueOf(frs.Dai_Bao_Xiu_Cnt__c));
    }
 
    private Integer valueOf(Decimal d) {
        if(d == null) {
            return 0;
        }
        return Integer.valueOf(d);
    }
}