高章伟
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
public with sharing class TransferApplyDetailController {
    //OCSM_BP5-35 邮件模板 公用调拨明细
    public Id taId{get;set;}
    public String varType{get;set;}
    public List<TransferApplyDetail__c> tadList {get;set;}
    public String gatherName{get;set;}
    public List<String>  title{get;set;}
    public List<String>  column {get;set;}
    private static final Map<String, Schema.FieldSet> FSMAP = Schema.SObjectType.TransferApplyDetail__c.fieldSets.getMap();
    public String  getInit(){
        Schema.FieldSet fs = FSMAP.get(gatherName);//TransferEmail
        List<FieldSetMember> fsmList = fs.getFields();
        // 获得字段集中的字段名
        title = new List<String>();
        column = new List<String>();
        for (FieldSetMember fsm : fsmList) {
            if(fsm.getLabel().contains('(Sys)')){
                title.add(fsm.getLabel().replace('(Sys)',''));
            }else{
                title.add(fsm.getLabel()); 
            }
            column.add(fsm.getFieldPath());
        }
        List<TransferApplyDetail__c> tadTempList = new List<TransferApplyDetail__c>();
        String soql = 'SELECT  Asset__c,TransferApplySummary__c,TransferType__c,Add_Request_demo_time__c ';
        for (Integer i=0;i<column.size();i++) {
            soql += ',' + column[i];
        }
        soql += ' FROM TransferApplyDetail__c '; 
        soql += ' WHERE  TransferApply__c = \''+taId+'\''; 
        if(String.isNotBlank(varType) && varType == 'cancel'){
            soql += ' AND Cancel_Time__c != null ';
            soql += ' AND Cancel_Select__c = true'; 
            soql += ' AND Inspection_result__c != \'NG\'';           
        }else{
            soql += ' AND Cancel_Select__c = False';
        }
        if(String.isNotBlank(varType) && varType == 'wp'){
            soql += ' AND After_Inspection_time_F__c != null AND Inspection_result_after_F__c != null AND Inspection_result_after_NG_F__c != \'维修\'';
            soql += ' AND IsPerfect__c = False';               
        }
        if(String.isNotBlank(varType) && varType == 'IsPerfect'){
            soql += ' AND IsPerfect__c = true';
            soql += ' AND Arrival_in_wh__c = False';                
        }
        if(String.isNotBlank(varType) && varType == 'add'){
            soql += ' AND Create_State__c = 1';
        }
        if(String.isNotBlank(varType) && varType == 'add'){
            soql += ' ORDER BY  Add_Request_demo_time__c DESC nulls first,TransferApplySummary__c,Name';
        }else{
            soql += ' ORDER BY  TransferApplySummary__c,Name';
        }
        tadTempList = Database.query(soql);
        if(String.isNotBlank(varType) && varType == 'add'){
            TransferApplyDetail__c t;
            List<TransferApplyDetail__c> addList = new List<TransferApplyDetail__c>();
            for (TransferApplyDetail__c tt : tadTempList) {
                if (t == null) {
                    t = tt;
                }
                if (t.Add_Request_demo_time__c != tt.Add_Request_demo_time__c) {
                    break;
                }
                addList.add(tt);
            }
            //if(addList != null && addList.size()>0){
            tadTempList = null;
            tadTempList = addList;
            //}
        }
        Map<String,TransferApplyDetail__c> tempMap = new Map<String,TransferApplyDetail__c>();
        for(TransferApplyDetail__c temp:tadTempList){
            String tempKey = temp.TransferApplySummary__c;
            if(String.isNotBlank(temp.Fixture_Model_No_F__c)){
                tempKey += temp.Fixture_Model_No_F__c;
            }
            if(String.isNotBlank(temp.SerialNumber__c)){
                tempKey += temp.SerialNumber__c;
            }
            if(tempMap.containsKey(tempKey)){
                TransferApplyDetail__c  tad = tempMap.get(tempKey);
                //调拨数量  待废弃调拨数  待修理调拨数  丢失调拨数
                if(String.isNotBlank(temp.TransferType__c) && temp.TransferType__c == '待废弃'){
                    tad.VF_TransferCount_Abandoned__c += 1;
                }else if(String.isNotBlank(temp.TransferType__c) && temp.TransferType__c == '待修理'){
                    tad.VF_TransferCount_Repair__c += 1;
                }else if(String.isNotBlank(temp.TransferType__c) && temp.TransferType__c == '丢失找回'){
                    tad.VF_TransferCount_Lost__c += 1;
                }else{
                    tad.VF_TransferCount__c += 1;
                }
                tempMap.put(tempKey,tad);
            }else{
                temp.VF_TransferCount_Abandoned__c = 0;
                temp.VF_TransferCount_Repair__c = 0;
                temp.VF_TransferCount_Lost__c = 0;
                temp.VF_TransferCount__c = 0;
                if(String.isNotBlank(temp.TransferType__c) && temp.TransferType__c == '待废弃'){
                    temp.VF_TransferCount_Abandoned__c = 1;
                }else if(String.isNotBlank(temp.TransferType__c) && temp.TransferType__c == '待修理'){
                    temp.VF_TransferCount_Repair__c = 1;
                }else if(String.isNotBlank(temp.TransferType__c) && temp.TransferType__c == '丢失找回'){
                    temp.VF_TransferCount_Lost__c = 1;
                }else{
                    temp.VF_TransferCount__c = 1;
                }
                tempMap.put(tempKey,temp);
            }
        }
        tadList = (List<TransferApplyDetail__c>)tempMap.values();
        return '';
    }
}