Repository navigation
Expand file tree
/
Copy pathPxAction.java
More file actions
executable file
·615 lines (534 loc) · 18.3 KB
/
Copy pathPxAction.java
File metadata and controls
executable file
·615 lines (534 loc) · 18.3 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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
package px;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import admin.Admin;
import basis.Excel;
import basis.Hfsession;
import basis.ResultUtils;
import sun.java2d.pipe.SpanShapeRenderer.Simple;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import util.Page;
import util.StringHelp;
import com.opensymphony.xwork2.ActionSupport;
public class PxAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private Map result;
private PxInfo pxInfo;
private String uuid;
private String keyword;
private String trainType;
private String yandm;
private List<PxInfo> list;
private File excelPath;
private Integer type;
private String orderField;
private String orderDirection;
private Page page = new Page();
private int currentPage = 1;
private String pageType;
private String exportType;
private String month;
private String year;
@Override
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
Admin admin = (Admin) session.getAttribute("admin");
if (admin != null) {
return SUCCESS;
} else {
return ERROR;
}
}
public String getPxInfoList() {
Session session = Hfsession.init();
Map<String, Object> map = new HashMap<String, Object>();
// List<Roster> list = new ArrayList<Roster>();
// Page page = new Page();
page.setEveryPage(15);
page.setCurrentPage(1);
Date dateNow = new Date();
Calendar c = Calendar.getInstance();
c.setTime(dateNow);
c.add(Calendar.MONTH, 1);
Date nextDate = c.getTime();
Calendar now = Calendar.getInstance();
String year1 = now.get(Calendar.YEAR)+"";
Integer m = now.get(Calendar.MONTH) + 1;
String month1 = (now.get(Calendar.MONTH) + 1)+"";
if(m<10){
month1="0"+m;
}
if(year==null && month==null){
year=year1;
month=month1;
yandm =year1+"-"+month1;
}else{
if(Integer.parseInt(month)<10){
month="0"+month;
}
yandm = year+"-"+month;
}
//System.out.println("==================year-month==============="+yandm);
try {
String hql = "select count(*) from PxInfo where 1=1 ";
if (keyword != null && !keyword.equals("")) {
hql += "and name like :name ";
}
if (trainType != null && !trainType.equals("")) {
hql += "and trainType like :trainType ";
}
if ("3".equals(pageType)) {
hql += " and dueToDate >= :dateNow and dueToDate <= :nextDate ";
}
if ("4".equals(pageType)) {
hql += " and licenseStatus = :licenseStatus ";
}
//需要补考人员
if ("5".equals(pageType)) {
hql += " and ( theoryResults< :theoryResults or actualResults< :actualResults) ";
hql += " and (FirstRetesttheoryResults< :FirstRetesttheoryResults or FirstRetestactualResults< :FirstRetestactualResults) " ;
hql += " and (SecondRetesttheoryResults< :SecondRetesttheoryResults or SecondRetestactualResults< :SecondRetestactualResults)";
}
//补考未通过人员
if ("6".equals(pageType)) {
hql += " and ( FirstRetesttheoryResults< :FirstRetesttheoryResults or FirstRetestactualResults< :FirstRetestactualResults) ";
hql += "and ( SecondRetesttheoryResults< :SecondRetesttheoryResults or SecondRetestactualResults< :SecondRetestactualResults) ";
hql += "and ( ThirdRetesttheoryResults< :ThirdRetesttheoryResults or ThirdRetestactualResults< :ThirdRetestactualResults) ";
hql += "and ( theoryResults< :theoryResults or actualResults< :actualResults)";
}
hql += " and signupDate like :signupDate ";
Query query = session.createQuery(hql);
query.setParameter("signupDate", "%" + yandm + "%");
if (keyword != null && !keyword.equals("")) {
query.setParameter("name", "%" + keyword + "%");
}
if (trainType != null && !trainType.equals("")) {
query.setParameter("trainType", "%" + trainType + "%");
}
if ("3".equals(pageType)) {
query.setParameter("dateNow", dateNow);
query.setParameter("nextDate", nextDate);
}
if ("4".equals(pageType)) {
query.setParameter("licenseStatus", "未领证");
}
if ("5".equals(pageType)) {
query.setParameter("theoryResults",60);
query.setParameter("actualResults", 60);
query.setParameter("FirstRetesttheoryResults", 60);
query.setParameter("FirstRetestactualResults", 60);
query.setParameter("SecondRetesttheoryResults", 60);
query.setParameter("SecondRetestactualResults", 60);
}
if ("6".equals(pageType)) {
query.setParameter("theoryResults",60);
query.setParameter("actualResults", 60);
query.setParameter("FirstRetesttheoryResults", 60);
query.setParameter("FirstRetestactualResults", 60);
query.setParameter("SecondRetesttheoryResults", 60);
query.setParameter("SecondRetestactualResults", 60);
query.setParameter("ThirdRetesttheoryResults", 60);
query.setParameter("ThirdRetestactualResults", 60);
}
Long count = (Long) query.uniqueResult();
//System.out.println("===========count================"+count);
page.setTotalCount(Integer.parseInt(String.valueOf(count)));
String sql = "from PxInfo where 1=1 ";
if ("3".equals(pageType)) {
sql += " and dueToDate >= :dateNow and dueToDate <= :nextDate ";
}
if ("4".equals(pageType)) {
sql += " and licenseStatus = :licenseStatus ";
}
//需要补考人员
if ("5".equals(pageType)) {
sql += " and ( theoryResults< :theoryResults or actualResults< :actualResults) ";
sql += " and (FirstRetesttheoryResults< :FirstRetesttheoryResults or FirstRetestactualResults< :FirstRetestactualResults) " ;
sql += " and (SecondRetesttheoryResults< :SecondRetesttheoryResults or SecondRetestactualResults< :SecondRetestactualResults)";
}
//补考未通过人员
if ("6".equals(pageType)) {
sql += " and ( FirstRetesttheoryResults< :FirstRetesttheoryResults or FirstRetestactualResults< :FirstRetestactualResults) ";
sql += "and ( SecondRetesttheoryResults< :SecondRetesttheoryResults or SecondRetestactualResults< :SecondRetestactualResults) ";
sql += "and ( ThirdRetesttheoryResults< :ThirdRetesttheoryResults or ThirdRetestactualResults< :ThirdRetestactualResults) ";
sql += "and ( theoryResults< :theoryResults or actualResults< :actualResults)";
}
if (keyword != null && !keyword.equals("")) {
sql += "and name like :name ";
}
if (trainType != null && !trainType.equals("")) {
sql += "and trainType like :trainType ";
}
sql += "and signupDate like :signupDate ";
Query q = session.createQuery(sql);
q.setParameter("signupDate","%" + yandm + "%");
if (keyword != null && !keyword.equals("")) {
q.setParameter("name", "%" + keyword + "%");
}
if (trainType != null && !trainType.equals("")) {
q.setParameter("trainType", "%" + trainType + "%");
}
if ("3".equals(pageType)) {
q.setParameter("dateNow", dateNow);
q.setParameter("nextDate", nextDate);
}
if ("4".equals(pageType)) {
q.setParameter("licenseStatus", "未领证");
}
if ("5".equals(pageType)) {
q.setParameter("theoryResults",60);
q.setParameter("actualResults", 60);
q.setParameter("FirstRetesttheoryResults", 60);
q.setParameter("FirstRetestactualResults", 60);
q.setParameter("SecondRetesttheoryResults", 60);
q.setParameter("SecondRetestactualResults", 60);
}
if ("6".equals(pageType)) {
q.setParameter("theoryResults",60);
q.setParameter("actualResults", 60);
q.setParameter("FirstRetesttheoryResults", 60);
q.setParameter("FirstRetestactualResults", 60);
q.setParameter("SecondRetesttheoryResults", 60);
q.setParameter("SecondRetestactualResults", 60);
q.setParameter("ThirdRetesttheoryResults", 60);
q.setParameter("ThirdRetestactualResults", 60);
}
q.setFirstResult((currentPage - 1) * 20);
q.setMaxResults(20);
list = q.list();
page.setTotalPage((int) Math.ceil(count / 20.0));
page.setHasPrePage(currentPage > 1);
page.setHasNextPage(currentPage < (int) (Math.ceil(count / 20.0)));
Hfsession.close();
} catch (Exception e) {
e.printStackTrace();
}
switch (pageType) {
case "1":
return "PXALL";
case "2":
return "PXJFGK";
case "3":
return "PXJJDQZS";
case "4":
return "PXWLZ";
case "5":
return "PXneedRetest";
case "6":
return "PXRetestFail";
default:
return ERROR;
}
}
public String delPxInfo() {
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
Map<String, Object> map = new HashMap<String, Object>();
try {
Query q = session.createQuery("from PxInfo where uuid =:uuid").setParameter("uuid", uuid);
pxInfo = (PxInfo) q.uniqueResult();
session.delete(pxInfo);
map.put("statusCode", 200);
ResultUtils.toJson(ServletActionContext.getResponse(), map);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
}finally{
Hfsession.close();
}
return SUCCESS;
}
public String addPxInfo() {
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Map<String, Object> map = new HashMap<String, Object>();
try {
if (pxInfo.getUuid() == null || "".equals(pxInfo.getUuid())) {
//System.out.println("=============pxInfo.getSignupDate()====================="+pxInfo.getSignupDate());
//pxInfo.setSignupDate(sdf.format(date));
session.save(pxInfo);
} else {
session.update(pxInfo);
}
map.put("statusCode", 200);
ResultUtils.toJson(ServletActionContext.getResponse(), map);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}finally{
Hfsession.close();
}
return SUCCESS;
}
public String inDialog() {
return SUCCESS;
}
public String editPxInfo() {
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
try {
Query q = session.createQuery("from PxInfo where uuid =:uuid").setParameter("uuid", uuid);
pxInfo = (PxInfo) q.uniqueResult();
//System.out.println("修改==+"+pxInfo.getName());
tx.commit();
if (pxInfo == null) {
return ERROR;
}
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
finally{
Hfsession.close();
}
return SUCCESS;
}
public String exportPxInfo() {
List<Object> listObject = new ArrayList<>();
List<PxInfo> listPxInfo = new ArrayList<>();
HttpServletRequest request = ServletActionContext.getRequest();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String exptrainType =request.getParameter("exptrainType");
String exyear =request.getParameter("year");
String exmonth =request.getParameter("month");
// try {
// if(extrainType!=null && !"".equals(extrainType)){
// exptrainType = new String(extrainType.getBytes("iso8859-1"),"utf-8");
// }
// } catch (UnsupportedEncodingException e1) {
// e1.printStackTrace();
// }
Session session = Hfsession.init();
//Transaction tx = session.beginTransaction();
Map<String, Object> map = new HashMap<String, Object>();
try {
Query q;
Date dateNow = new Date();
Calendar c = Calendar.getInstance();
c.setTime(dateNow);
c.add(Calendar.MONTH, 1);
Date nextDate = c.getTime();
if(Integer.parseInt(month)<10){
month="0"+exmonth;
}
yandm = year+"-"+month;
//System.out.println("==================================yandm=================================="+yandm);
if (exportType != null && "1".equals(exportType)) {
String sql="from PxInfo where 1 = 1 and dueToDate >= :dateNow and dueToDate <= :nextDate ";
if(exptrainType!=null && !"".equals(exptrainType)){
sql+=" and trainType like :trainType ";
}
sql += " and signupDate like :signupDate ";
q = session.createQuery(sql);
q.setParameter("signupDate","%" + yandm + "%");
if(exptrainType!=null && !"".equals(exptrainType)){
q.setParameter("trainType", "%"+exptrainType+"%");
}
q.setParameter("dateNow", dateNow);
q.setParameter("nextDate", nextDate);
}else if(exportType != null && "2".equals(exportType)){
String sql="from PxInfo where 1 = 1 and licenseStatus = :licenseStatus ";
if(exptrainType!=null && !"".equals(exptrainType)){
sql+=" and trainType like :trainType ";
}
sql += " and signupDate like :signupDate ";
q = session.createQuery(sql);
q.setParameter("signupDate","%" + yandm + "%");
if(exptrainType!=null && !"".equals(exptrainType)){
q.setParameter("trainType", "%"+exptrainType+"%");
}
q.setParameter("licenseStatus", "未领证");
}else {
String sql ="from PxInfo where 1 = 1";
if(exptrainType!=null && !"".equals(exptrainType)){
sql+=" and trainType like:trainType ";
}
sql += "and signupDate like :signupDate ";
q = session.createQuery(sql);
q.setParameter("signupDate","%" + yandm + "%");
if(exptrainType!=null && !"".equals(exptrainType)){
q.setParameter("trainType", "%"+exptrainType+"%");
}
}
listPxInfo = q.list();
//tx.commit();
for (int i = 0; i < listPxInfo.size();) {
PxInfo r = listPxInfo.get(i);
r.setUuid(++i + "");
listObject.add(r);
}
String[] str = new String[] { "序号", "培训日期", "姓名", "姓别", "身份证", "文化程度", "单位/个人", "联系电话", "单位联系人", "单位电话",
"培训点", "类别", "考试情况", "标准金额", "优惠金额", "缴费情况","收据号", "到期日期","考试日期", "领证情况",
"生效日期","证书编号","学员编号","第一次补考费用","第二次补考费用","第三次补考费用","第一次补考收据号","第二次补考收据号","第三次补考收据号","理论成绩",
"实际操作成绩","第一次补考理论成绩","第二次补考理论成绩","第三次补考理论成绩","第一次补考实操成绩","第二次补考实操成绩","第三次补考实操成绩"
};
String title="国通企业培训人员花名册--"+sdf.format(new Date())+".xls";
if(exptrainType!=null && !"".equals(exptrainType)){
title="国通企业培训部("+exptrainType+")人员花名册--"+sdf.format(new Date())+".xls";
}
Excel.exportExcel(title, str, listObject);
map.put("statusCode", 200);
ResultUtils.toJson(ServletActionContext.getResponse(), map);
} catch (Exception e) {
e.printStackTrace();
}finally{
Hfsession.close();
}
return SUCCESS;
}
public String importExcel() throws IOException, ParseException {
Map<String, Object> map = new HashMap<String, Object>();
try {
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
InputStream fis = new FileInputStream(excelPath);
list = new ArrayList<>();
list = PxService.importExcel(fis);
System.out.println("=============LISTSIZE===================="+list.size());
for (PxInfo info : list) {
session.save(info);
}
tx.commit();
map.put("statusCode", 200);
ResultUtils.toJson(ServletActionContext.getResponse(), map);
} catch (FileNotFoundException e) {
e.printStackTrace();
return ERROR;
}finally{
Hfsession.close();
}
return SUCCESS;
}
public String getTrainType() {
return trainType;
}
public void setTrainType(String trainType) {
this.trainType = trainType;
}
public String getYandm() {
return yandm;
}
public void setYandm(String yandm) {
this.yandm = yandm;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public String getExportType() {
return exportType;
}
public void setExportType(String exportType) {
this.exportType = exportType;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public String getPageType() {
return pageType;
}
public void setPageType(String pageType) {
this.pageType = pageType;
}
public Map getResult() {
return result;
}
public void setResult(Map result) {
this.result = result;
}
public PxInfo getPxInfo() {
return pxInfo;
}
public void setPxInfo(PxInfo pxInfo) {
this.pxInfo = pxInfo;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
public List<PxInfo> getList() {
return list;
}
public void setList(List<PxInfo> list) {
this.list = list;
}
public File getExcelPath() {
return excelPath;
}
public void setExcelPath(File excelPath) {
this.excelPath = excelPath;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getOrderField() {
return orderField;
}
public void setOrderField(String orderField) {
this.orderField = orderField;
}
public String getOrderDirection() {
return orderDirection;
}
public void setOrderDirection(String orderDirection) {
this.orderDirection = orderDirection;
}
public Page getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String inrosters() {
return SUCCESS;
}
}