HrmImportOperation.jsp
15.2 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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<%@ page import="weaver.general.Util,weaver.file.*,java.util.*" %>
<%@ page import="weaver.soa.hrm.HrmService"%>
<%@ page import="weaver.soa.hrm.ExportResult"%>
<%@ page import="weaver.hrm.company.DepartmentComInfo"%>
<%@ page import="weaver.hrm.job.JobTitlesComInfo"%>
<%@ page import="weaver.hrm.resource.ResourceComInfo"%>
<%@ page import="weaver.hrm.location.LocationComInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/systeminfo/init_wev8.jsp" %>
<jsp:useBean id="ExcelParse" class="weaver.file.ExcelParse" scope="page" />
<jsp:useBean id="FileManage" class="weaver.file.FileManage" scope="page" />
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="RecordSet2" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="SubCompanyComInfo" class="weaver.hrm.company.SubCompanyComInfo" scope="page" />
<jsp:useBean id="departmentComInfo" class="weaver.hrm.company.DepartmentComInfo" scope="page" />
<jsp:useBean id="JobTitlesComInfo" class="weaver.hrm.job.JobTitlesComInfo" scope="page" />
<%!
private weaver.conn.RecordSet rst=new weaver.conn.RecordSet();
private List incorrectList=new ArrayList();//保存导入不符合要求的数据
private Map errMsgMap=new HashMap();//存储记录导入失败的原因
private void addIncorrectName(String name,String errMsg){
ExportResult exp=new ExportResult();
exp.setLastname(name);
exp.setOperation("82");//新建
exp.setStatus("498");//失败
errMsgMap.put(name,errMsg);
this.incorrectList.add(exp);
}
private boolean isExistSubcompany(int subCompanyId,String subCompanyName){//如果不加id无法确定分部和部门之间的上下级关系
String sql="SELECT * FROM HrmSubcompany WHERE id="+subCompanyId+" AND (subcompanyName='"+subCompanyName+"' OR subcompanydesc='"+subCompanyName+"')";
rst.executeSql(sql);
return rst.next()?true:false;
}
/** 根据部门名称获取部门Id,如果不存在返回-1 */
//private List[] getDepartmentId(String depName){
//return getDepartmentId(depName, "");
//}
private List[] getDepartmentId(String depName, String departid){
departid = Util.null2String(departid);
String sql="select id,subcompanyid1 from HrmDepartment where departmentmark='"+depName+"' OR departmentname='"+depName+"'";
rst.executeSql(sql);
List[] arList=null;
if(rst.next()){
arList=new ArrayList[2];
arList[0]=new ArrayList();
arList[1]=new ArrayList();
do{
String id_tmp = rst.getString("id");
if(!"".equals(departid) && !id_tmp.equals(departid)){
continue;
}
arList[0].add(rst.getString("id"));
arList[1].add(rst.getString("subcompanyid1"));
}while(rst.next());
}
return arList;
}
/** 根据岗位名称获取岗位Id,如果不存在则返回-1 */
private int getJobTitleId(String jobTitleName,int depId){
String string=this.getSubDepString(String.valueOf(depId))+"0";
String sql="select id from HrmJobTitles where jobDepartmentId IN ("+depId+") AND (jobtitlemark='"+jobTitleName+"' OR jobtitlename='"+jobTitleName+"')";
rst.executeSql(sql);
return rst.next()?rst.getInt(1):-1;
}
private Map subDeps=null;
private String getSubDepString(String depId){
String subDepString=depId+",";
if(subDeps.containsKey(depId)){
List list1=(List)subDeps.get(depId);
for(int i=0;i<list1.size();i++){
String obj=list1.get(i).toString();
if(!subDeps.containsKey(depId)){
subDepString+=obj+",";
continue;
}else subDepString+=this.getSubDepString(obj);//递归求出所有下级
}
}
return subDepString;
}
private Map initSubDep(DepartmentComInfo dep){
DepartmentComInfo deptcominfo=dep;
Map subDep=new HashMap();
String depId=null;
String supDepId=null;
List list1=null;
while(deptcominfo.next()){
String dept=deptcominfo.getDepartmentname();
String deptmark=deptcominfo.getDepartmentmark();
depId=deptcominfo.getDepartmentid();
supDepId=deptcominfo.getDepartmentsupdepid(depId);
supDepId=supDepId.equalsIgnoreCase("")?"0":supDepId;
if(supDepId.equalsIgnoreCase("0"))continue;
if(!subDep.containsKey(supDepId)){
list1=new ArrayList();
subDep.put(supDepId,list1);
}else list1=(List)subDep.get(supDepId);
list1.add(depId);
}
return subDep;
}
%>
<%
FileUploadToPath fu = new FileUploadToPath(request) ; // 非压缩上传
String filename = fu.uploadFiles("excelfile") ;
HrmService service = new HrmService();
service.setExp_result(new ArrayList());
errMsgMap.clear();
incorrectList.clear();
this.subDeps=this.initSubDep(departmentComInfo);//初始化求出所有下级映射关系
if(!filename.equals("")) {
// 找出对应用户列表存入缓存
ExcelParse.init( filename ) ;
int recordercount = 0 ;
while( true ) {
recordercount ++ ;
String workcode = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "1" ) ).trim() ;
String lastname = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "2" ) ).trim() ;
String sex = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "3" ) ).trim() ;
String departid = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "4" ) ).trim() ;
String department = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "5" ) ).trim() ;
String subcompany = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "6" ) ).trim() ;
String jobtitle = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "7" ) ).trim() ;
String manager = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "8" ) ).trim() ;
String status = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "9" ) ).trim() ;
String location = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "10" ) ).trim() ;
String loginid = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "11" ) ).trim() ;
String password = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "12" ) ).trim() ;
String seclevel = Util.null2String( ExcelParse.getValue("1", ""+recordercount , "13" ) ).trim() ;
//标题行
if( recordercount == 1 ) continue ;
if( lastname.equals("") ) break ;
List[] ids=this.getDepartmentId(department,departid);
int errNum=-21159;//默认为部门不存在
int depId=0;
int jobTitleId=0;
int subCompanyId=0;
boolean isfalsh = true;
String islawful = "select count(id) from HrmDepartment where departmentmark='"+department+"' OR departmentname='"+department+"'";
RecordSet2.executeSql(islawful);
if(RecordSet2.next()){
if(RecordSet2.getInt(1)>1 && "".equals(departid)){
errNum=-22258;
isfalsh = false;
}
}
if(ids!=null && isfalsh){//
List list1=ids[0];
List list2=ids[1];
for(int i=0;i<list1.size();i++){
errNum=-21159;//默认为部门不存在
depId=Integer.parseInt(list1.get(i).toString());
subCompanyId=Integer.parseInt(list2.get(i).toString());
jobTitleId=this.getJobTitleId(jobtitle,depId);
if(jobTitleId>0){
if(isExistSubcompany(subCompanyId,subcompany)){
errNum=0;break;//如果存在则直接跳出循环
}else errNum=-21161;
}else errNum=-21160;
}
}
if(errNum<0){
String errMsg=SystemEnv.getHtmlLabelName(-errNum,user.getLanguage());
if(errNum==-21161)errMsg+=SystemEnv.getHtmlLabelName(21168,user.getLanguage());
this.addIncorrectName(lastname,errMsg);//添加不存在列表
continue;
}
// add user
weaver.soa.hrm.User u=new weaver.soa.hrm.User();
if(!workcode.equals("")) {
u.setWorkcode(workcode);
}
u.setLastname(lastname);
if(!sex.equals(""))
u.setSex(sex);
u.setDepartmentid(depId);
/* DepartmentComInfo deptcominfo=new DepartmentComInfo();
if(!department.equals("")){
while(deptcominfo.next()) {
String dept=deptcominfo.getDepartmentname();
String deptmark=deptcominfo.getDepartmentmark();
if(!subcompany.equals("")){
String subname=SubCompanyComInfo.getSubCompanyname(deptcominfo.getSubcompanyid1());
String subdesc=SubCompanyComInfo.getSubCompanydesc(deptcominfo.getSubcompanyid1());
if(!subname.equals(subcompany)&&!subdesc.equals(subcompany))continue;
}
if(dept.equals(department)||deptmark.equals(department)) {
u.setDepartmentid(Integer.parseInt(deptcominfo.getDepartmentid()));
}
}
}
*/
u.setJobtitle(jobTitleId);
/* if(!jobtitle.equals("")){
JobTitlesComInfo jtcominfo=new JobTitlesComInfo();
while(jtcominfo.next()) {
String deptid=jtcominfo.getDepartmentid();
if(deptcominfo.getDepartmentname(deptid).equals(department)){
String companyid=deptcominfo.getSubcompanyid1(deptid);
if(SubCompanyComInfo.getSubCompanyname(companyid).equals(subcompany)){
String jt=jtcominfo.getJobTitlesname();
String jtmark=jtcominfo.getJobTitlesmark();
if(jt.equals(jobtitle)||jtmark.equals(jobtitle)) {
u.setJobtitle(Integer.parseInt(jtcominfo.getJobTitlesid()));
}
}
}
}
}*/
if (!manager.equals("")) {
String mg_name = "";
String hrm_workcode = "";
int checkmanager = manager.indexOf("/");
if(checkmanager > 0){
mg_name = manager.substring(0,manager.lastIndexOf("/"));
hrm_workcode = manager.substring(manager.lastIndexOf("/")+1,manager.length());
RecordSet.executeSql("select id from hrmresource where lastname = '"+mg_name+"' and workcode = '"+hrm_workcode+"'");
if(RecordSet.next()){
u.setManagerid(RecordSet.getInt("id"));
}
}else{
ResourceComInfo rscominfo = new ResourceComInfo();
while(rscominfo.next()) {
String name = rscominfo.getLastname();
if(name.equals(manager)) {
u.setManagerid(Integer.parseInt(rscominfo.getResourceid()));
break;
}
}
}
}
if(!status.equals("")){
if(status.equals(SystemEnv.getHtmlLabelName(15710,user.getLanguage()))){
u.setStatus(0);
}
if(status.equals(SystemEnv.getHtmlLabelName(15711,user.getLanguage()))){
u.setStatus(1);
}
if(status.equals(SystemEnv.getHtmlLabelName(480,user.getLanguage()))){
u.setStatus(2);
}
if(status.equals(SystemEnv.getHtmlLabelName(15844,user.getLanguage()))){
u.setStatus(3);
}
if(status.equals(SystemEnv.getHtmlLabelName(6094,user.getLanguage()))){
u.setStatus(4);
}
if(status.equals(SystemEnv.getHtmlLabelName(6091,user.getLanguage()))){
u.setStatus(5);
}
if(status.equals(SystemEnv.getHtmlLabelName(6092,user.getLanguage()))){
u.setStatus(6);
}
if(status.equals(SystemEnv.getHtmlLabelName(2245,user.getLanguage()))){
u.setStatus(7);
}
if(status.equals(SystemEnv.getHtmlLabelName(1831,user.getLanguage()))){
u.setStatus(10);
}
}
if(!location.equals("")){
LocationComInfo locationcominfo=new LocationComInfo();
while(locationcominfo.next()) {
String name=locationcominfo.getLocationname();
if(name.equals(location)) {
u.setLocationid(Integer.parseInt(locationcominfo.getLocationid()));
}
}
}
//modify by ds 人员导入可以导入登陆账号为空的人员
/*
if(!loginid.equals("")){
u.setLoginid(loginid);
}
*/
u.setLoginid(loginid);
if(!password.equals("")){
u.setPassword(password);
}
if(!seclevel.equals("")){
try{
u.setSeclevel((int) Double.parseDouble(seclevel));
}catch(Exception e){
}
}
service.addUser(u);
}
FileManage.DeleteFile( filename ) ;
}
%>
<HTML><HEAD>
<LINK href="/css/Weaver_wev8.css" type=text/css rel=STYLESHEET>
<SCRIPT language="javascript" src="/js/weaver_wev8.js"></script>
</head>
<%
String imagefilename = "/images/hdMaintenance_wev8.gif";
String titlename = SystemEnv.getHtmlLabelName(17887,user.getLanguage());
String needfav ="1";
String needhelp ="";
%>
<BODY>
<%@ include file="/systeminfo/TopTitle_wev8.jsp" %>
<%@ include file="/systeminfo/RightClickMenuConent_wev8.jsp" %>
<%@ include file="/systeminfo/RightClickMenu_wev8.jsp" %>
<table width=100% height=100% border="0" cellspacing="0" cellpadding="0">
<colgroup>
<col width="10">
<col width="">
<col width="10">
<tr>
<td height="10" colspan="3"></td>
</tr>
<tr>
<td ></td>
<td valign="top">
<TABLE class=Shadow>
<tr>
<td valign="top">
<TABLE class=ListStyle cellspacing=1 >
<COLGROUP>
<COL width="20%">
<COL width="20">
<COL width="20">
<COL width="40">
<TBODY>
<TR class=Header>
<TH colSpan=4><%=SystemEnv.getHtmlLabelName(17887,user.getLanguage())+SystemEnv.getHtmlLabelName(320,user.getLanguage())%></TH></TR>
<TR class=Header>
<TD><%=SystemEnv.getHtmlLabelName(195,user.getLanguage())%></TD>
<TD><%=SystemEnv.getHtmlLabelName(104,user.getLanguage())%></TD>
<TD><%=SystemEnv.getHtmlLabelName(602,user.getLanguage())%></TD>
<TD><%=SystemEnv.getHtmlLabelName(22259,user.getLanguage())%></TD>
</TR>
<TR class=Line><TD colspan="3" ></TD></TR>
<%
List list=service.getExp_result();
list.addAll(incorrectList);
ExportResult[] result=(ExportResult[]) list.toArray(new ExportResult[list.size() ]);
int needchange = 0;
for(int i=0;i<result.length;i++){
int isfirst = 1;
try{
if(needchange ==0){
needchange = 1;
%>
<TR class=datalight>
<%
}else{
needchange=0;
%>
<TR class=datadark>
<%
}
String styleInfo=(result[i].getStatus()=="498")?" style=\"color:red\"":"";
%>
<TD> <%=result[i].getLastname()%>
</TD>
<TD><%=SystemEnv.getHtmlLabelName(Util.getIntValue(result[i].getOperation()),user.getLanguage())%>
</TD>
<%if(result[i].getStatus()=="15242"){%>
<TD<%=styleInfo%>><%
out.print(SystemEnv.getHtmlLabelName(Util.getIntValue(result[i].getStatus()),user.getLanguage()));
%>
</TD><%}else{%>
<TD<%=styleInfo%>><%
out.print(SystemEnv.getHtmlLabelName(Util.getIntValue(result[i].getStatus()),user.getLanguage()));
Object obj=errMsgMap.get(result[i].getLastname());
if(obj!=null)out.print("("+obj.toString()+")");
%>
</TD><%}%>
<TD>
<%if(result[i].getStatus()=="15242") {%>
<%=departmentComInfo.getDepartmentname(""+result[i].getDepartment())%>/<%=JobTitlesComInfo.getJobTitlesname(""+result[i].getJobtitle())%>
<%}%>
</TD>
</TR>
<%isfirst=0;
}catch(Exception e){
}
}
%>
</TBODY></TABLE>
</td>
</tr>
</TABLE>
</td>
<td></td>
</tr>
<tr>
<td height="10" colspan="3"></td>
</tr>
</table>
</BODY></HTML>