hrmtreeXML.jsp
13.4 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.*" %>
<%@ page import="net.sf.json.*"%>
<%@ page import="weaver.hrm.resource.TreeNode"%>
<%@ page import="weaver.general.*,weaver.file.Prop" %>
<%@ page import="weaver.hrm.company.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@page import="java.util.ArrayList"%>
<%@page import="weaver.hrm.resource.ResourceComInfo"%>
<%@page import="weaver.conn.RecordSet"%>
<%@page import="weaver.hrm.appdetach.AppDetachComInfo"%>
<%@page import="weaver.hrm.resource.MutilResourceBrowser"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<jsp:useBean id="MutilResourceBrowser" class="weaver.hrm.resource.MutilResourceBrowser" scope="page" /><jsp:useBean id="CompanyVirtualComInfo" class="weaver.hrm.companyvirtual.CompanyVirtualComInfo" scope="page" /><jsp:useBean id="CompanyComInfo" class="weaver.hrm.company.CompanyComInfo" scope="page" />
<%!
public TreeNode getSubCompanyTreeList(TreeNode companyTreeList, String subId, ArrayList selectedids, String isNoAccount, User user, String sqlwhere) throws Exception {
getDepartTreeList(companyTreeList, subId, "0",selectedids,isNoAccount, user, sqlwhere);
AppDetachComInfo adci = new AppDetachComInfo(user);
//adci.resetAppDetachInfo();
List<String> allowsubcompany=adci.getAlllowsubcompany();//能查看的分部
List<String> allowsubcompanyview=adci.getAlllowsubcompanyview();//能查看的分部含必要的上级
//Map subMap = adci.getAllDetachSubcompanyInfo(String.valueOf(user.getUID()));
SubCompanyComInfo rs = new SubCompanyComInfo();
rs.setTofirstRow();
while (rs.next()) {
String id = rs.getSubCompanyid();
String supsubcomid = rs.getSupsubcomid();
if (supsubcomid.equals(""))supsubcomid = "0";
if (!supsubcomid.equals(subId))continue;
boolean flag = true;
if(!adci.isNotCheckUserAppDetach()){
flag = false;
if(allowsubcompany.contains(id)){
flag = true;
}
if(!flag && allowsubcompanyview.contains(id)){
flag = true;
}
}
if(!flag)continue;
String name = rs.getSubCompanyname();
String canceled = rs.getCompanyiscanceled();
TreeNode subCompanyNode = new TreeNode();
subCompanyNode.setName(name);
subCompanyNode.setId(id);
subCompanyNode.setNodeid("subcom_"+id);
subCompanyNode.setPid(subId);
subCompanyNode.setIcon("/images/treeimages/Home_wev8.gif");
subCompanyNode.setNocheck("N");
if(hasChild("subcompany",id)){
subCompanyNode.setIsParent("true");
}
subCompanyNode.setType("subcom");
if(!"1".equals(canceled))companyTreeList.AddChildren(subCompanyNode);
//getSubCompanyTreeList(subCompanyNode, id);
}
return companyTreeList;
}
public TreeNode getDepartTreeList(TreeNode departTreeList, String subId, String departmentId, ArrayList selectedids, String isNoAccount, User user, String sqlwhere) throws Exception {
DepartmentComInfo rsDepartment = new DepartmentComInfo();
rsDepartment.setTofirstRow();
if(departmentId.length()>0){
getResourceTreeList(departTreeList, departmentId,selectedids, isNoAccount, user, sqlwhere);
}
AppDetachComInfo adci = new AppDetachComInfo(user);
//adci.resetAppDetachInfo();
//Map deptMap = adci.getAllDetachDepartmentInfo(String.valueOf(user.getUID()));
List<String> allowsubcompany=adci.getAlllowsubcompany();//能查看的分部
List<String> allowdepartment=adci.getAlllowdepartment();//能查看的部门
List<String> allowdepartmentview=adci.getAlllowdepartmentview();//能查看的部门含必要的上级
while (rsDepartment.next()) {
if(departmentId.equals(rsDepartment.getDepartmentid()))continue;
String supdepid = rsDepartment.getDepartmentsupdepid();
if (departmentId.equals("0") && supdepid.equals(""))supdepid = "0";
if (!(rsDepartment.getSubcompanyid1().equals(subId) && (supdepid.equals(departmentId)||(!rsDepartment.getSubcompanyid1(supdepid).equals(subId)&&departmentId.equals("0"))))) continue;
String id = rsDepartment.getDepartmentid();
String subcompanyid1 = rsDepartment.getSubcompanyid1();
String name = rsDepartment.getDepartmentname();
String canceled = rsDepartment.getDeparmentcanceled();
boolean flag = true;
if(!adci.isNotCheckUserAppDetach()){
flag = false;
if(allowdepartment.contains(id)){
flag = true;
}
if(!flag && allowdepartmentview.contains(id)){
flag = true;
}
if(!flag && allowsubcompany.contains(subcompanyid1)){
flag = true;
}
}
if(!flag)continue;
TreeNode departmentNode = new TreeNode();
departmentNode.setName(name);
departmentNode.setNocheck("Y");
departmentNode.setId(id);
departmentNode.setNodeid("dept_"+id);
departmentNode.setIcon("/images/treeimages/subCopany_Colse_wev8.gif");
if (hasChild("dept", id)) {
departmentNode.setIsParent("true");
}
departmentNode.setType("dept");
if(!"1".equals(canceled))departTreeList.AddChildren(departmentNode);
}
return departTreeList;
}
public TreeNode getResourceTreeList(TreeNode resourceTreeList, String departmentId, ArrayList selectedids, String isNoAccount, User user, String sqlwhere) throws Exception {
DepartmentComInfo rsDepartment = new DepartmentComInfo();
ResourceComInfo ResourceComInfo = new ResourceComInfo();
rsDepartment.setTofirstRow();
String sql = "select hr.id, lastname, hr.pinyinlastname, hr.subcompanyid1, hr.jobtitle, loginid, account "
+ "from hrmresource hr, hrmdepartment t2 "
+ "where hr.departmentid=t2.id and t2.id=" + departmentId ;
AppDetachComInfo adci = new AppDetachComInfo();
if(sqlwhere.length()>0)sqlwhere=" and " +sqlwhere;
sqlwhere+=" and hr.status in (0,1,2,3)";
if(adci.isUseAppDetach()){
String appdetawhere = adci.getScopeSqlByHrmResourceSearch(user.getUID()+"",true,"resource_hr");
String tempstr= (appdetawhere!=null&&!"".equals(appdetawhere)?(" and " + appdetawhere):"");
sqlwhere+=tempstr;
}
if(sqlwhere.length()>0)sql+=sqlwhere;
sql += " order by hr.dsporder ";
//System.out.println(sql);
RecordSet rs1 = new RecordSet();
rs1.executeSql(sql);
while (rs1.next()) {
String id = rs1.getString("id");
String lastname = rs1.getString("lastname");
String pinyinlastname = rs1.getString("pinyinlastname");
String jobtitle = rs1.getString("jobtitle");
String loginid = rs1.getString("loginid");
jobtitle = MutilResourceBrowser.getJobTitlesname(id,user);
lastname="<span id='pinyinlastname' style='display:none'>"+pinyinlastname+"</span><span id='lastname'>"+lastname+"</span><span id='jobtitlename' style='color:#929390;margin-left:15px;margin-right:2px;'>"+jobtitle+"</span>";
TreeNode resourceNode = new TreeNode();
resourceNode.setName(lastname);
resourceNode.setId(id);
resourceNode.setNodeid("resource_"+id);
resourceNode.setIcon(ResourceComInfo.getMessagerUrls(id));
resourceNode.setNocheck("N");
if(selectedids.contains(id)){
resourceNode.setIsHidden("true");
}
if(!isNoAccount.equals("1")){
if(loginid.length()==0)resourceNode.setIsHidden("true");
}
resourceNode.setType("resource");
resourceTreeList.AddChildren(resourceNode);
}
return resourceTreeList;
}
/**
* 指定节点下是否有子节点
* @param type com:分部;dept:部门
* @param id 节点id
* @return boolean
* @throws Exception
*/
private boolean hasChild(String type, String id) throws Exception {
boolean hasChild = false;
if (type.equals("subcompany")) {
SubCompanyComInfo rs = new SubCompanyComInfo();
rs.setTofirstRow();
while (rs.next()) {
if (rs.getSupsubcomid().equals(id) && !"1".equals(rs.getCompanyiscanceled()))
hasChild = true;
}
DepartmentComInfo rsDepartment = new DepartmentComInfo();
rsDepartment.setTofirstRow();
while (rsDepartment.next()) {
if (rsDepartment.getSubcompanyid1().equals(id) && !"1".equals(rsDepartment.getDeparmentcanceled())) {
hasChild = true;
}
}
} else if (type.equals("dept")) {
DepartmentComInfo rsDepartment = new DepartmentComInfo();
rsDepartment.setTofirstRow();
while (rsDepartment.next()) {
String str = rsDepartment.getSubcompanyid1(id);
if (rsDepartment.getSubcompanyid1().equals(str) && rsDepartment.getDepartmentsupdepid().equals(id) && !"1".equals(rsDepartment.getDeparmentcanceled()))
hasChild = true;
}
if(!hasChild){
ResourceComInfo rsResource = new ResourceComInfo();
rsResource.setTofirstRow();
while (rsResource.next()) {
String str = rsResource.getDepartmentID();
if (str.equals(id))
hasChild = true;
}
}
}
return hasChild;
}
private String getResourceNumJson(String nodeids, ArrayList selectedids, String isNoAccount, String sqlwhere)throws Exception{
JSONArray jsonArr = new JSONArray();
String[] arr_nodeid =Util.TokenizerString2(nodeids,",");
RecordSet rs = new RecordSet();
for(String nodeid:arr_nodeid){
String type = nodeid.split("_")[0];
String id = nodeid.split("_")[1];
String sql = "select count(*) from hrmresource hr where 1=1 ";
if(type.equals("dept")){
sql += " and departmentid in ( "+ DepartmentComInfo.getAllChildDepartId(id, id) +" )";
}else if(type.equals("subcom")){
sql += " and subcompanyid1 in ( "+ SubCompanyComInfo.getAllChildSubcompanyId(id, id) +" )";
}else if(type.equals("com")){
}
if(sqlwhere.length()>0)sql+=" and " +sqlwhere;
String noAccountSql="";
if(!isNoAccount.equals("1")){
noAccountSql=" and loginid is not null "+(rs.getDBType().equals("oracle")?"":" and loginid<>'' ");
}
sql += noAccountSql;
String ids = "";
for(int i=0;selectedids!=null&&i<selectedids.size();i++){
if(ids.length()>0)ids+=",";
ids+=selectedids.get(i);
}
if(ids.length()>0)sql +=" and id not in ("+ids+")";
rs.executeSql(sql);
if(rs.next()){
JSONObject tmp = new JSONObject();
tmp.put("nodeid",nodeid);
tmp.put("nodenum",rs.getInt(1));
//System.out.println(rs.getInt(1));
jsonArr.add(tmp);
}
}
return jsonArr.toString();
}
%>
<%
response.setHeader("cache-control", "no-cache");
response.setHeader("pragma", "no-cache");
response.setHeader("expires", "Mon 1 Jan 1990 00:00:00 GMT");
User user = HrmUserVarify.getUser (request , response) ;
if(user == null) return ;
String id=Util.null2String(request.getParameter("id"));
String type=Util.null2String(request.getParameter("type"));
String virtualtype=Util.null2String(request.getParameter("virtualtype"));
String selectedids=Util.null2String(request.getParameter("selectedids"));
String alllevel=Util.null2String(request.getParameter("alllevel"));
String isNoAccount=Util.null2String(request.getParameter("isNoAccount"));
String sqlwhere=Util.null2String(request.getParameter("sqlwhere"));
String cmd=Util.null2String(request.getParameter("cmd"));
selectedids = MutilResourceBrowser.getExcludeSqlWhere(selectedids,alllevel,isNoAccount,user, sqlwhere);
ArrayList selectList = new ArrayList();
if(selectedids.length()>0){
String[] tmp_selectedids = selectedids.split(",");
for(String selectedid:tmp_selectedids){
selectList.add(selectedid);
}
}
JSONArray jObject = null;
TreeNode envelope=new TreeNode();
if(cmd.equals("getVirtualType")){
if(CompanyVirtualComInfo.getCompanyNum()>0){
TreeNode root = new TreeNode();
TreeNode node = new TreeNode();
if(CompanyComInfo.getCompanyNum()>0){
CompanyComInfo.setTofirstRow();
while(CompanyComInfo.next()){
node = new TreeNode();
String dfvirtualtypename = CompanyComInfo.getCompanyname();
node.setId(CompanyComInfo.getCompanyid());
node.setName(dfvirtualtypename.length()>4?dfvirtualtypename.substring(0,4):dfvirtualtypename);
root.AddChildren(node);
}
}
if(CompanyVirtualComInfo.getCompanyNum()>0){
CompanyVirtualComInfo.setTofirstRow();
while(CompanyVirtualComInfo.next()){
node = new TreeNode();
String dfvirtualtypename = CompanyVirtualComInfo.getVirtualType();
node.setId(CompanyVirtualComInfo.getCompanyid());
node.setName(dfvirtualtypename.length()>4?dfvirtualtypename.substring(0,4):dfvirtualtypename);
root.AddChildren(node);
}
}
jObject = JSONArray.fromObject(root.getChildren());
out.println(jObject.toString());
}
}else if(cmd.equals("getNum")){
String jsonData = "";
String nodeids=Util.null2String(request.getParameter("nodeids"));
jsonData = getResourceNumJson(nodeids, selectList,isNoAccount, sqlwhere);
out.println(jsonData);
}else{
if(id.equals("")){
//初始化
TreeNode root = new TreeNode();
String companyname = CompanyComInfo.getCompanyname("1");
root.setNodeid("com_"+1);
root.setName(companyname);
root.setId("0");
root.setOpen("true");
root.setTarget("_self");
root.setIcon("/images/treeimages/global_wev8.gif");
root.setType("com");
getSubCompanyTreeList(root,"0",selectList,isNoAccount, user, sqlwhere);
jObject = JSONArray.fromObject(root);
}else if(type.equals("subcom")){
getSubCompanyTreeList(envelope,id,selectList,isNoAccount, user, sqlwhere);
ArrayList<TreeNode> lsChild = envelope.getChildren();
jObject = JSONArray.fromObject(lsChild);
}else if(type.equals("dept")){
DepartmentComInfo DepartmentComInfo = new DepartmentComInfo();
String subId = DepartmentComInfo.getSubcompanyid1(id);
getDepartTreeList(envelope,subId,id,selectList,isNoAccount, user, sqlwhere);
ArrayList<TreeNode> lsChild = envelope.getChildren();
jObject = JSONArray.fromObject(lsChild);
}
//System.out.println(jObject.toString());
out.println(jObject.toString());
}
%>