buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
public with sharing class PersonalProcessInstanceController {
    public List<ProcessInfo> accPIList { get; private set; }
    public List<ProcessInfo> conPIList { get; private set; }
    public List<ProcessInfo> oppPIList { get; private set; }
    public List<ProcessInfo> odrPIList { get; private set; }
    public List<ProcessInfo> othPIList { get; private set; }
 
    private String userId;
 
    public Integer getAccPIListSize() {
        return accPIList.size();
    }
 
    public Integer getConPIListSize() {
        return conPIList.size();
    }
 
    public Integer getOppPIListSize() {
        return oppPIList.size();
    }
 
    public Integer getOdrPiListSize() {
        return odrPIList.size();
    }
 
    public Integer getOthPIListSize() {
        return othPIList.size();
    }
 
    public PersonalProcessInstanceController() {
        userId = ApexPages.currentPage().getParameters().get('uid');
        if (userId == null || userId == '') {
            userId = UserInfo.getUserId();
        }
    }
 
    public PageReference init() {
        List<ProcessInstanceWorkitem> piwList = [select id, ActorId, CreatedDate, ElapsedTimeInDays, OriginalActorId,
                                                        ProcessInstance.TargetObjectId, ProcessInstance.Targetobject.Name, ProcessInstance.Status, ProcessInstance.SubmittedbyId, ProcessInstance.Submittedby.Name
                                                   from ProcessInstanceWorkitem
                                                  where ActorId = :userId
                                                  order by ProcessInstance.TargetobjectId, CreatedDate asc];
 
        Integer lineNo = 0;
        accPIList = new List<ProcessInfo>();
        conPIList = new List<ProcessInfo>();
        oppPIList = new List<ProcessInfo>();
        odrPIList = new List<ProcessInfo>();
        othPIList = new List<ProcessInfo>();
        if (piwList.size() > 0) {
            for (ProcessInstanceWorkitem piw : piwList) {
                lineNo += 1;
                String targetObjectId = piw.ProcessInstance.TargetObjectId;
                if (targetObjectId.startsWith('001') == true) {
                    // account
                    ProcessInfo newpi = new ProcessInfo(lineNo, piw, 'account');
                    accPIList.add(newpi);
                } else if (targetObjectId.startsWith('003') == true) {
                    // contact
                    ProcessInfo newpi = new ProcessInfo(lineNo, piw, 'contact');
                    conPIList.add(newpi);
                } else if (targetObjectId.startsWith('006') == true) {
                    // opportunity
                    ProcessInfo newpi = new ProcessInfo(lineNo, piw, 'opportunity');
                    oppPIList.add(newpi);
                } else if (targetObjectId.startsWith('801') == true) {
                    // order
                    ProcessInfo newpi = new ProcessInfo(lineNo, piw, 'order');
                    odrPIList.add(newpi);
                } else {
                    // others
                    ProcessInfo newpi = new ProcessInfo(lineNo, piw, 'other');
                    othPIList.add(newpi);
                }
            }
        }
 
        return null;
    }
 
    class ProcessInfo {
        public Integer lineNo { get; private set; }
        public ProcessInstanceWorkitem piw { get; private set; }
        public Decimal elapsedTimeInDays { get; private set; }
        // accpunt,contact,opportunity,order,other
        public String pType { get; private set; }
 
        public ProcessInfo(Integer in_no, ProcessInstanceWorkitem in_piw, String in_pType) {
            lineNo = in_no;
            piw = in_piw;
            pType = in_pType;
            elapsedTimeInDays = in_piw.ElapsedTimeInDays;
            elapsedTimeInDays = elapsedTimeInDays.setScale(1);
        }
    }
}