Blame view

src/com/fh/controller/sunvote/student/StudentController.java 12.7 KB
5b03edef   孙向锦   更新协议
1
2
3
4
5
6
7
8
9
10
  package com.fh.controller.sunvote.student;
  
  import java.io.PrintWriter;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
7d60b75e   孙向锦   添加班级-1
11
  
5b03edef   孙向锦   更新协议
12
  import javax.annotation.Resource;
7d60b75e   孙向锦   添加班级-1
13
  
5b03edef   孙向锦   更新协议
14
15
16
17
18
  import org.springframework.beans.propertyeditors.CustomDateEditor;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.WebDataBinder;
  import org.springframework.web.bind.annotation.InitBinder;
  import org.springframework.web.bind.annotation.RequestMapping;
b5cf92b7   孙向锦   批量上传学生名单
19
  import org.springframework.web.bind.annotation.RequestParam;
5b03edef   孙向锦   更新协议
20
  import org.springframework.web.bind.annotation.ResponseBody;
b5cf92b7   孙向锦   批量上传学生名单
21
  import org.springframework.web.multipart.MultipartFile;
5b03edef   孙向锦   更新协议
22
  import org.springframework.web.servlet.ModelAndView;
7d60b75e   孙向锦   添加班级-1
23
  
5b03edef   孙向锦   更新协议
24
25
  import com.fh.controller.base.BaseController;
  import com.fh.entity.Page;
f4b16acc   孙向锦   修改学号排序问题
26
27
28
  import com.fh.service.sunvote.classroster.ClassRosterManager;
  import com.fh.service.sunvote.student.StudentManager;
  import com.fh.service.sunvote.term.TermManager;
5b03edef   孙向锦   更新协议
29
  import com.fh.util.AppUtil;
b5cf92b7   孙向锦   批量上传学生名单
30
31
  import com.fh.util.Const;
  import com.fh.util.FileUpload;
f4b16acc   孙向锦   修改学号排序问题
32
  import com.fh.util.Jurisdiction;
b5cf92b7   孙向锦   批量上传学生名单
33
  import com.fh.util.ObjectExcelRead;
5b03edef   孙向锦   更新协议
34
35
  import com.fh.util.ObjectExcelView;
  import com.fh.util.PageData;
b5cf92b7   孙向锦   批量上传学生名单
36
  import com.fh.util.PathUtil;
5b03edef   孙向锦   更新协议
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  
  /** 
   * 说明:学生管理
   * 创建人:Elvis
   * 创建时间:2018-04-28
   */
  @Controller
  @RequestMapping(value="/student")
  public class StudentController extends BaseController {
  	
  	String menuUrl = "student/list.do"; //菜单地址(权限用)
  	@Resource(name="studentService")
  	private StudentManager studentService;
  	
7d60b75e   孙向锦   添加班级-1
51
52
53
  	@Resource(name="classrosterService")
  	private ClassRosterManager classrosterService;
  	
a479f295   孙向锦   添加了报表逻辑
54
55
56
  	@Resource(name="termService")
  	private TermManager termService;
  	
5b03edef   孙向锦   更新协议
57
58
59
60
61
62
63
  	/**保存
  	 * @param
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/save")
  	public ModelAndView save() throws Exception{
  		logBefore(logger, Jurisdiction.getUsername()+"新增Student");
5b03edef   孙向锦   更新协议
64
65
  		ModelAndView mv = this.getModelAndView();
  		PageData pd = new PageData();
053a45fd   孙向锦   解析excel bug,去掉空行
66
  		pd = this.getPageData(); 	 
5b03edef   孙向锦   更新协议
67
68
69
70
71
72
  		studentService.save(pd);
  		mv.addObject("msg","success");
  		mv.setViewName("save_result");
  		return mv;
  	}
  	
7d60b75e   孙向锦   添加班级-1
73
74
75
76
77
78
79
  	/**保存
  	 * @param
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/save2")
  	public ModelAndView save2() throws Exception{
  		logBefore(logger, Jurisdiction.getUsername()+"新增Student");
7d60b75e   孙向锦   添加班级-1
80
81
  		ModelAndView mv = this.getModelAndView();
  		PageData pd = new PageData();
253c2bb1   孙向锦   班级学生管理
82
  		pd = this.getPageData();
7d60b75e   孙向锦   添加班级-1
83
84
  		String studentID = this.get32UUID();
  		pd.put("ID", studentID);
253c2bb1   孙向锦   班级学生管理
85
  		pd.put("STUDENT_ID", studentID);
a479f295   孙向锦   添加了报表逻辑
86
  		pd.put("SNO", pd.get("NUMBER"));
7d60b75e   孙向锦   添加班级-1
87
88
89
90
91
  		studentService.save(pd);
  		
  		String termID = pd.getString("TERM_ID");
  		String classID = pd.getString("CLASS_ID");
  		pd.put("CLASSROSTER_ID", get32UUID());
253c2bb1   孙向锦   班级学生管理
92
  		pd.put("TEAMID", termID);
7d60b75e   孙向锦   添加班级-1
93
94
95
96
97
98
  		pd.put("SCLASS_ID", classID);
  		classrosterService.save(pd);
  		
  		
  		
  		mv.addObject("msg","success");
6429ab88   孙向锦   remove
99
  		mv.setViewName("save_result2");
7d60b75e   孙向锦   添加班级-1
100
101
102
  		return mv;
  	}
  	
b5cf92b7   孙向锦   批量上传学生名单
103
104
105
106
107
108
109
110
111
112
  	
  	
  	/**打开上传EXCEL页面
  	 * @return
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/goUploadExcel")
  	public ModelAndView goUploadExcel()throws Exception{
  		ModelAndView mv = this.getModelAndView();
  		mv.addObject("pd", getPageData());
053a45fd   孙向锦   解析excel bug,去掉空行
113
  		
fd0087a8   孙向锦   添加英语语言
114
115
116
117
118
  		if(isChineseLanguageClient()){
  			mv.setViewName("sunvote/student/uploadexcel");
  		}else{
  			mv.setViewName("sunvote/student/en_uploadexcel");
  		}
b5cf92b7   孙向锦   批量上传学生名单
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
  		return mv;
  	}
  	
  	
  	/**EXCEL导入到数据库
  	 * @param file
  	 * @return
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/readExcel")
  	public ModelAndView readExcel(
  			@RequestParam(value="excel",required=false) MultipartFile file
  			) throws Exception{
  		logBefore(logger,Jurisdiction.getUsername() + "从EXCEL导入到数据库");
  		ModelAndView mv = this.getModelAndView();
  		PageData tpd = getPageData();
  		PageData pd = new PageData();
  		String termID = tpd.getString("TERM_ID");
00af725f   孙向锦   修复bug
137
138
139
  		if(termID == null || "".equals(termID.trim())){
  			termID = getTermId();
  		}
b5cf92b7   孙向锦   批量上传学生名单
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  		String classID = tpd.getString("CLASS_ID");
  		if (null != file && !file.isEmpty()) {
  			String filePath = PathUtil.getClasspath() + Const.FILEPATHFILE;								//文件上传路径
  			String fileName =  FileUpload.fileUp(file, filePath, "userexcel");							//执行上传
  			List<PageData> listPd = (List)ObjectExcelRead.readExcel(filePath, fileName, 0, 0, 0);		//执行读EXCEL操作,读出的数据导入List 2:从第3行开始;0:从第A列开始;0:第0个sheet
  			if(listPd.size() > 0 ){
  				pd= listPd.get(0);
  				for(int i = 1 ; i < listPd.size();i++){
  					PageData savePd = new PageData();
  					PageData temp = listPd.get(i);
  					for(int j = 0 ; ;j++){
  						if(temp.get("var" + j) == null){
  							break ;
  						}
053a45fd   孙向锦   解析excel bug,去掉空行
154
155
156
  						if(temp.get("var" + j) != null && !"".equals(temp.get("var" + j).toString())){
  							savePd.put(pd.getString("var" + j).toUpperCase(), temp.get("var" + j));
  						}
b5cf92b7   孙向锦   批量上传学生名单
157
158
  					}
  					if(!savePd.containsKey("ID")){
053a45fd   孙向锦   解析excel bug,去掉空行
159
160
161
  						if (savePd.values().size() > 0) {
  							String studentId = this.get32UUID();
  							savePd.put("ID", studentId);
00af725f   孙向锦   修复bug
162
163
  							savePd.put("CLASS_ID", classID);
  							
053a45fd   孙向锦   解析excel bug,去掉空行
164
165
166
167
168
169
170
171
172
  							studentService.save(savePd);
  
  							if (classID != null && termID != null) {
  								savePd.put("STUDENT_ID", studentId);
  								savePd.put("CLASSROSTER_ID", get32UUID());
  								savePd.put("TEAMID", termID);
  								savePd.put("SCLASS_ID", classID);
  								classrosterService.save(savePd);
  							}
b5cf92b7   孙向锦   批量上传学生名单
173
174
175
176
177
178
179
180
181
182
  						}
  						
  					}else{
  						studentService.edit(savePd);
  					}
  				}
  				
  			}
  		}
  		mv.addObject("msg","success");
3371dbc6   孙向锦   0720 版本
183
  		mv.setViewName("save_result2");
b5cf92b7   孙向锦   批量上传学生名单
184
185
186
187
  		return mv;
  	}
  	
  	
5b03edef   孙向锦   更新协议
188
189
190
191
192
193
194
  	/**删除
  	 * @param out
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/delete")
  	public void delete(PrintWriter out) throws Exception{
  		logBefore(logger, Jurisdiction.getUsername()+"删除Student");
5b03edef   孙向锦   更新协议
195
196
197
  		PageData pd = new PageData();
  		pd = this.getPageData();
  		studentService.delete(pd);
b5cf92b7   孙向锦   批量上传学生名单
198
199
  		pd.put("STUDENT_ID", pd.get("ID"));
  		classrosterService.delete(pd);
5b03edef   孙向锦   更新协议
200
201
202
203
204
205
206
207
208
209
210
  		out.write("success");
  		out.close();
  	}
  	
  	/**修改
  	 * @param
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/edit")
  	public ModelAndView edit() throws Exception{
  		logBefore(logger, Jurisdiction.getUsername()+"修改Student");
5b03edef   孙向锦   更新协议
211
212
213
214
215
216
217
218
219
  		ModelAndView mv = this.getModelAndView();
  		PageData pd = new PageData();
  		pd = this.getPageData();
  		studentService.edit(pd);
  		mv.addObject("msg","success");
  		mv.setViewName("save_result");
  		return mv;
  	}
  	
67dfaf5c   孙向锦   提交代码
220
  	
8942b440   孙向锦   提交code
221
222
223
224
225
226
227
228
229
230
231
  	/**修改
  	 * @param
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/edit2")
  	public ModelAndView edit2() throws Exception{
  		logBefore(logger, Jurisdiction.getUsername()+"修改Student");
  		ModelAndView mv = this.getModelAndView();
  		PageData pd = new PageData();
  		pd = this.getPageData();
  		studentService.edit(pd);
3371dbc6   孙向锦   0720 版本
232
233
  		mv.addObject("msg","success");
  		mv.setViewName("save_result2");
8942b440   孙向锦   提交code
234
235
236
  		return mv;
  	}
  	
5b03edef   孙向锦   更新协议
237
238
239
240
241
242
243
  	/**列表
  	 * @param page
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/list")
  	public ModelAndView list(Page page) throws Exception{
  		logBefore(logger, Jurisdiction.getUsername()+"列表Student");
5b03edef   孙向锦   更新协议
244
245
246
  		ModelAndView mv = this.getModelAndView();
  		PageData pd = new PageData();
  		pd = this.getPageData();
b5cf92b7   孙向锦   批量上传学生名单
247
  		String keywords = pd.getString("KEYWORDS");				//关键词检索条件
5b03edef   孙向锦   更新协议
248
249
250
251
252
253
254
255
256
257
258
259
  		if(null != keywords && !"".equals(keywords)){
  			pd.put("keywords", keywords.trim());
  		}
  		page.setPd(pd);
  		List<PageData>	varList = studentService.list(page);	//列出Student列表
  		mv.setViewName("sunvote/student/student_list");
  		mv.addObject("varList", varList);
  		mv.addObject("pd", pd);
  		mv.addObject("QX",Jurisdiction.getHC());	//按钮权限
  		return mv;
  	}
  	
7d60b75e   孙向锦   添加班级-1
260
261
262
263
264
265
266
  	/**列表
  	 * @param page
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/listcs")
  	public ModelAndView listClassStudent(Page page) throws Exception{
  		logBefore(logger, Jurisdiction.getUsername()+"列表Student");
7d60b75e   孙向锦   添加班级-1
267
268
269
270
271
  		ModelAndView mv = this.getModelAndView();
  		PageData pd = new PageData();
  		pd = this.getPageData();
  		page.setPd(pd);
  		List<PageData>	varList = studentService.datalistclassPage(page);	//列出Student列表
fd0087a8   孙向锦   添加英语语言
272
273
274
275
276
277
  		page.setLangIsChina(isChineseLanguageClient());
  		if(isChineseLanguageClient()){
  			mv.setViewName("sunvote/student/student_list2");
  		}else{
  			mv.setViewName("sunvote/student/en_student_list2");
  		}
7d60b75e   孙向锦   添加班级-1
278
279
280
281
282
283
  		mv.addObject("varList", varList);
  		mv.addObject("pd", pd);
  		mv.addObject("QX",Jurisdiction.getHC());	//按钮权限
  		return mv;
  	}
  	
5b03edef   孙向锦   更新协议
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
  	/**去新增页面
  	 * @param
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/goAdd")
  	public ModelAndView goAdd()throws Exception{
  		ModelAndView mv = this.getModelAndView();
  		PageData pd = new PageData();
  		pd = this.getPageData();
  		mv.setViewName("sunvote/student/student_edit");
  		mv.addObject("msg", "save");
  		mv.addObject("pd", pd);
  		return mv;
  	}	
  	
7d60b75e   孙向锦   添加班级-1
299
300
301
302
303
304
305
306
307
  	/**去新增页面
  	 * @param
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/goAdd2")
  	public ModelAndView goAdd2()throws Exception{
  		ModelAndView mv = this.getModelAndView();
  		PageData pd = new PageData();
  		pd = this.getPageData();
a479f295   孙向锦   添加了报表逻辑
308
  		pd.put("TERM_ID", getTermId());
fd0087a8   孙向锦   添加英语语言
309
310
311
312
313
  		if(isChineseLanguageClient()){
  			mv.setViewName("sunvote/student/student_edit2");
  		}else{
  			mv.setViewName("sunvote/student/en_student_edit2");
  		}
7d60b75e   孙向锦   添加班级-1
314
315
316
317
318
  		mv.addObject("msg", "save2");
  		mv.addObject("pd", pd);
  		return mv;
  	}	
  	
5b03edef   孙向锦   更新协议
319
320
321
322
323
324
325
  	 /**去修改页面
  	 * @param
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/goEdit")
  	public ModelAndView goEdit()throws Exception{
  		ModelAndView mv = this.getModelAndView();
7d60b75e   孙向锦   添加班级-1
326
327
328
329
330
331
332
333
334
335
336
337
338
339
  		PageData pd = this.getPageData();
  		pd = studentService.findById(pd);	//根据ID读取
  		mv.setViewName("sunvote/student/student_edit");
  		mv.addObject("msg", "edit");
  		mv.addObject("pd", pd);
  		return mv;
  	}	
  	/**去修改页面
  	 * @param
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/goEdit2")
  	public ModelAndView goEdit2()throws Exception{
  		ModelAndView mv = this.getModelAndView();
5b03edef   孙向锦   更新协议
340
341
  		PageData pd = new PageData();
  		pd = this.getPageData();
5b03edef   孙向锦   更新协议
342
  		pd = studentService.findById(pd);	//根据ID读取
fd0087a8   孙向锦   添加英语语言
343
344
345
346
347
  		if(isChineseLanguageClient()){
  			mv.setViewName("sunvote/student/student_edit2");
  		}else{
  			mv.setViewName("sunvote/student/en_student_edit2");
  		}
8942b440   孙向锦   提交code
348
  		mv.addObject("msg", "edit2");
5b03edef   孙向锦   更新协议
349
350
351
352
353
354
355
356
357
358
359
360
  		mv.addObject("pd", pd);
  		return mv;
  	}	
  	
  	 /**批量删除
  	 * @param
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/deleteAll")
  	@ResponseBody
  	public Object deleteAll() throws Exception{
  		logBefore(logger, Jurisdiction.getUsername()+"批量删除Student");
5b03edef   孙向锦   更新协议
361
362
363
364
365
366
367
368
  		PageData pd = new PageData();		
  		Map<String,Object> map = new HashMap<String,Object>();
  		pd = this.getPageData();
  		List<PageData> pdList = new ArrayList<PageData>();
  		String DATA_IDS = pd.getString("DATA_IDS");
  		if(null != DATA_IDS && !"".equals(DATA_IDS)){
  			String ArrayDATA_IDS[] = DATA_IDS.split(",");
  			studentService.deleteAll(ArrayDATA_IDS);
b5cf92b7   孙向锦   批量上传学生名单
369
  			classrosterService.deleteAllByStudentID(ArrayDATA_IDS);
5b03edef   孙向锦   更新协议
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
  			pd.put("msg", "ok");
  		}else{
  			pd.put("msg", "no");
  		}
  		pdList.add(pd);
  		map.put("list", pdList);
  		return AppUtil.returnObject(pd, map);
  	}
  	
  	 /**导出到excel
  	 * @param
  	 * @throws Exception
  	 */
  	@RequestMapping(value="/excel")
  	public ModelAndView exportExcel() throws Exception{
  		logBefore(logger, Jurisdiction.getUsername()+"导出Student到excel");
5b03edef   孙向锦   更新协议
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
  		ModelAndView mv = new ModelAndView();
  		PageData pd = new PageData();
  		pd = this.getPageData();
  		Map<String,Object> dataMap = new HashMap<String,Object>();
  		List<String> titles = new ArrayList<String>();
  		titles.add("学生姓名");	//1
  		titles.add("学籍号");	//2
  		titles.add("学号");	//3
  		titles.add("性别");	//4
  		titles.add("组号");	//5
  		titles.add("签到码");	//6
  		titles.add("家长姓名");	//7
  		titles.add("家长手机号");	//8
  		titles.add("键盘ID");	//9
  		titles.add("备注");	//10
  		dataMap.put("titles", titles);
  		List<PageData> varOList = studentService.listAll(pd);
  		List<PageData> varList = new ArrayList<PageData>();
  		for(int i=0;i<varOList.size();i++){
  			PageData vpd = new PageData();
  			vpd.put("var1", varOList.get(i).getString("NAME"));	    //1
  			vpd.put("var2", varOList.get(i).getString("SNO"));	    //2
  			vpd.put("var3", varOList.get(i).getString("NUMBER"));	    //3
  			vpd.put("var4", varOList.get(i).get("SEX").toString());	//4
  			vpd.put("var5", varOList.get(i).getString("GROUP"));	    //5
  			vpd.put("var6", varOList.get(i).getString("SIGN_NO"));	    //6
  			vpd.put("var7", varOList.get(i).getString("PARENT_NAME"));	    //7
  			vpd.put("var8", varOList.get(i).getString("PARENT_PHONE"));	    //8
  			vpd.put("var9", varOList.get(i).getString("KEYPAD_ID"));	    //9
  			vpd.put("var10", varOList.get(i).getString("REMARK"));	    //10
  			varList.add(vpd);
  		}
  		dataMap.put("varList", varList);
  		ObjectExcelView erv = new ObjectExcelView();
  		mv = new ModelAndView(erv,dataMap);
  		return mv;
  	}
  	
a479f295   孙向锦   添加了报表逻辑
424
425
426
427
428
429
430
431
  	public String getTermId()  throws Exception{
  		PageData pd = termService.findCurrentId();
  		if(pd != null){
  			return pd.getString("TERM_ID");
  		}
  		return null;
  	}
  	
5b03edef   孙向锦   更新协议
432
433
434
435
436
437
  	@InitBinder
  	public void initBinder(WebDataBinder binder){
  		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  		binder.registerCustomEditor(Date.class, new CustomDateEditor(format,true));
  	}
  }