田源
2025-01-09 8a166a60cfd1a2e593ffa103d10c0dc224fc8628
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package com.vci.client.workflow.user;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.vci.client.common.objects.UserEntityObject;
import com.vci.client.portal.utility.TableDataUtil;
import com.vci.client.workflow.delegate.ProcessCustomClientDelegate;
import com.vci.corba.workflow.data.FlowInstanceInfo;
 
public class VciWorkflowUserImpl implements WorkflowUserInterface {
    
    enum UserExpression{
        all("all", 0, "所有人"),
        creator("creator", 1, "拟稿人"),
        creatordept("creator.dept", 2, "拟稿人所在部门"),
        ownerdept("owner.dept", 3, "当前处理人所在部门"),
        allleader("allleader", 4, "所有领导"),
        allsecretary("allsecretary", 5, "所有秘书"),
        creatordeptleader("creator.dept.leader", 6, "拟稿人所在部门领导"),
        ownerdeptleader("owner.dept.leader", 7, "当前处理人所在部门领导"),
        owner("owner", 8, "当前节点处理人"),
        onenodealluser("onenode.alluser", 9 , "某一级别的所有人"),
        onenodemanager("onenode.manager", 10 , "某一节点处理人"),
        chooseByForm("chooseByForm", 11 , "从业务表单中选择"),
        ownerchilddept("owner.childdept", 12, "当前处理人的一级部门"),
        ownercustomorg("owner.customorg", 13, "当前人的自定义组"),//暂不处理
        custom("custom", 14, "反射类");
        
        private String value;
        private String explain;
        
        private UserExpression(String value, int index, String explain){
            this.value = value;
            this.explain = explain;
        }
    }
    
    private static VciWorkflowUserImpl instance = null;
    
    public static VciWorkflowUserImpl getInstance() {
        if(instance == null) {
            instance = new VciWorkflowUserImpl();
        }
        return instance;
    }
    
    private TableDataUtil util = new TableDataUtil();
    private String id = "";
    private UserEntityObject userObj = null;
    
    public List<String[]> getUserByExp(String exp, String executionId, UserEntityObject userObj) {
        if(exp == null | exp.length() == 0 | userObj == null) {
            return new ArrayList<String[]>();
        }
        this.userObj = userObj;
        this.id = executionId;
        for(UserExpression ue : UserExpression.values()) {
            if(exp.equals(ue.value)) {
                try {
                    return getUser(ue);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return new ArrayList<String[]>();
    }
    
    private List<String[]> getUser(UserExpression ue) throws Exception {
        List<Map<String, String>>  list = null;
        List<String[]> nullList = new ArrayList<String[]>();
        Map<String, String> conditionMap = new HashMap<String, String>();
        System.out.println(ue.explain);
        switch(ue) {
        case all:
            list = queryDate("personTemplete", null, "person");
            return turnIDList(list, "id");
        case creator:
            list = queryUser();
            return turnIDList(list, "id");
        case creatordept:
            list = queryDept();
            return turnIDList(list, "oid");
        case ownerdept:
            id = null;
            list = queryDept();
            return turnIDList(list, "oid");
        case allleader:
            conditionMap.put("islead", "1");
            list = queryDate("personTemplete", conditionMap, "person");
            return turnIDList(list, "id");
        case allsecretary:
            conditionMap.put("issecretary", "1");
            list = queryDate("personTemplete", conditionMap, "person");
            return turnIDList(list, "oid");
        case creatordeptleader:
            list = queryDeptLeader();
            return turnIDList(list, "oid");
        case ownerdeptleader:
            id = null;
            list = queryDeptLeader();
            return turnIDList(list, "oid");
        case owner:
            id = null;
            list = queryUser();
            return turnIDList(list, "oid");
        case onenodealluser:
            break;
        case onenodemanager:
            break;
        case chooseByForm:
            break;
        case ownerchilddept:
            id = null;
            list = queryDept();
            if(list == null) {
                return nullList;
            }
            String oid = list.get(0).get("oid");
            conditionMap.put("parentdept", oid);
            list = queryDate("DepartmentQueryTemplate", conditionMap, "department");
            return turnIDList(list, "oid");
        case ownercustomorg:
            break;
        case custom:
            if(id != null && id.length() > 0) {
                WorkflowUserInterface inter = (WorkflowUserInterface) (Class
                        .forName(id).newInstance());
                return inter.getUserByExp(null, null, this.userObj);
            }
            
            break;
        }
        return nullList;
    }
 
    /**
     * 返回长度为4的数组,第一个为id(user时)或oid(其他情况),第二个是name,其他为空
     * @param list
     * @param key
     * @return
     */
    private List<String[]> turnIDList(List<Map<String, String>> list, String key) {
        List<String[]> idList = new ArrayList<String[]>();
        if(list != null) {
            for(Map<String, String> map : list) {
                String[] strs = new String[4];
                strs[0] = map.get(key);
                strs[1] = map.get("name");
                idList.add(strs);
            }
        }
        return idList;
    }
    
    private List<Map<String, String>> queryDeptLeader() throws Exception{
        List<Map<String, String>> list = queryDept();
        if(list == null) {
            return new ArrayList<Map<String, String>>();
        }
        Map<String, String> conditionMap = new HashMap<String, String>();
        conditionMap = new HashMap<String, String>();
        conditionMap.put("f_oid", list.get(0).get("oid"));
        conditionMap.put("isparttime", "0");
        list = queryDate("deptPersonTemplate", conditionMap, "deptperson");
        List<Map<String, String>> index = new ArrayList<Map<String, String>>();
        for(Map<String, String> map : list) {
            if("1".equals(map.get("islead"))) {
                index.add(map);
            }
        }
        return index;
    }
    
    private List<Map<String, String>> queryDept() throws Exception{
        List<Map<String, String>> list = queryUser();
        if(list.size() != 1) {
            return new ArrayList<Map<String, String>>();
        }
        String t_oid = list.get(0).get("oid");
        Map<String, String> conditionMap = new HashMap<String, String>();
        conditionMap.put("t_oid", t_oid);
        conditionMap.put("isparttime", "0");
        return queryDate("queryDeptTemplate", conditionMap, "deptperson");
    }
    
    private List<Map<String, String>> queryUser() throws Exception{
        String userName = "";
        if(id == null || id.length() == 0) {                
            userName = userObj.getUserName();
        } else {
            ProcessCustomClientDelegate pccd = new ProcessCustomClientDelegate(userObj);
            FlowInstanceInfo fii = pccd.getFlowInstanceInfo(id);
            userName = fii.creator;
        }
        Map<String, String> conditionMap = new HashMap<String, String>();
        conditionMap.put("id", userName);
        return queryDate("personTemplete", conditionMap, "person");
    }
    
    private List<Map<String, String>> queryDate(String qtName, Map<String, String> conditionMap, String type) {
        List<Map<String, String>> dataModel = null;
        Map<String, String> queryColumnsMap = new HashMap<String, String>();
        queryColumnsMap.put("*", "标题");
        try {
            dataModel = util.getObjectDataList(qtName, null,
                    conditionMap , null, null, type,
                    queryColumnsMap, null, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(dataModel == null) {
            dataModel = new ArrayList<Map<String, String>>();
        }
        return dataModel;
    }
 
    public String getAttrbuteByCondition(Map<String, String> items,
            String attr) {
        String str = items.get(attr) == null ? "" : items.get(attr);
        return str;
    }
 
}