TeacherController.java 18.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 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
package com.fh.controller.sunvote.teacher;

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;

import javax.annotation.Resource;

import org.apache.shiro.crypto.hash.SimpleHash;
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;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fh.controller.api.ResponseGson;
import com.fh.controller.base.BaseController;
import com.fh.entity.Page;
import com.fh.service.api.V1Manager;
import com.fh.service.sunvote.school.SchoolManager;
import com.fh.service.sunvote.teacher.TeacherManager;
import com.fh.service.system.fhlog.FHlogManager;
import com.fh.service.system.user.UserManager;
import com.fh.util.AppUtil;
import com.fh.util.Jurisdiction;
import com.fh.util.ObjectExcelView;
import com.fh.util.PageData;
import com.fh.util.Tools;

/**
 * 说明:教师 创建人:Elvis 创建时间:2018-04-26
 */
@Controller
@RequestMapping(value = "/teacher")
public class TeacherController extends BaseController {

	String menuUrl = "teacher/list.do"; // 菜单地址(权限用)
	@Resource(name = "teacherService")
	private TeacherManager teacherService;

	@Resource(name = "schoolService")
	private SchoolManager schoolService;

	@Resource(name = "userService")
	private UserManager userService;

	@Resource(name = "fhlogService")
	private FHlogManager FHLOG;
	
	@Resource(name = "v1Service")
	private V1Manager v1Service;

	/**
	 * 保存
	 * 
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/save")
	public ModelAndView save() throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "新增Teacher");
		if (!Jurisdiction.buttonJurisdiction(menuUrl, "add")) {
			return null;
		} // 校验权限
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("ID", this.get32UUID());
		teacherService.save(pd);

		pd.put("USER_ID", pd.getString("ID")); // ID 主键
		pd.put("LAST_LOGIN", ""); // 最后登录时间
		pd.put("IP", ""); // IP
		pd.put("STATUS", "0"); // 状态
		pd.put("SKIN", "default");
		pd.put("RIGHTS", "");
		pd.put("USERNAME", pd.getString("ACCOUT"));
		pd.put("ROLE_ID", "57bb1e6f138247a0b05cc721a5da1b64");
		pd.put("PASSWORD",
				new SimpleHash("SHA-1", pd.getString("ACCOUT"), pd
						.getString("PASSWORD")).toString()); // 密码加密

		if (null == userService.findByUsername(pd)) { // 判断用户名是否存在
			userService.saveU(pd); // 执行保存
			FHLOG.save(Jurisdiction.getUsername(),
					"新增系统用户:" + pd.getString("USERNAME"));
		}

		mv.addObject("msg", "success");
		mv.setViewName("save_result");
		return mv;
	}

	/**
	 * 删除
	 * 
	 * @param out
	 * @throws Exception
	 */
	@RequestMapping(value = "/delete")
	public void delete(PrintWriter out) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "删除Teacher");
		if (!Jurisdiction.buttonJurisdiction(menuUrl, "del")) {
			return;
		} // 校验权限
		PageData pd = new PageData();
		pd = this.getPageData();                        
		pd.put("USER_ID", pd.get("ID"));
		teacherService.delete(pd);
		userService.deleteU(pd);
		out.write("success");
		out.close();
	}

	/**
	 * 修改
	 * 
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/edit")
	public ModelAndView edit() throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "修改Teacher");
		if (!Jurisdiction.buttonJurisdiction(menuUrl, "edit")) {
			return null;
		} // 校验权限
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		teacherService.edit(pd);

		/*
		 * pd.put("USER_ID", pd.getString("ID")); //ID 主键 pd.put("LAST_LOGIN",
		 * ""); //最后登录时间 pd.put("IP", ""); //IP pd.put("STATUS", "0"); //状态
		 * pd.put("SKIN", "default"); pd.put("RIGHTS", ""); pd.put("USERNAME",
		 * pd.getString("ACCOUT")); pd.put("ROLE_ID",
		 * "57bb1e6f138247a0b05cc721a5da1b64"); pd.put("PASSWORD", new
		 * SimpleHash("SHA-1", pd.getString("ACCOUT"),
		 * pd.getString("PASSWORD")).toString()); //密码加密
		 * 
		 * userService.saveU(pd);
		 */

		mv.addObject("msg", "success");
		mv.setViewName("save_result");
		return mv;
	}

	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/teach_paper")
	public ModelAndView teach_paper(Page page) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Paper");
		String userId = this.getUserID();
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		mv.setViewName("sunvote/teacher/teach_paper");
		pd.put("userId", userId);
		mv.addObject("pd", pd);
		return mv;
	}
	
	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/teach_paper1")
	public ModelAndView teach_paper1(Page page) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Paper");
		String userId = this.getUserID();
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		mv.setViewName("sunvote/teacher/teach_paper1");
		pd.put("userId", userId);
		mv.addObject("pd", pd);
		return mv;
	}
	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/test_list")
	public ModelAndView test_list(Page page) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Paper");
		String userId = this.getUserID();
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("userId", userId);
		mv.setViewName("sunvote/teacher/test_list");
		mv.addObject("pd", pd);
		return mv;
	}
	
	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/paper_view")
	public ModelAndView paper_view(Page page) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Paper");
		String userId = this.getUserID();
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("userId", userId);
		pd.put("subject_id",  getSubjectID(userId));
		mv.setViewName("sunvote/teacher/paper_view");
		mv.addObject("pd", pd);
		return mv;
	}
	
	private String getSubjectID(String userId) {
		PageData pt = new PageData();
		pt.put("TEACHER_ID", userId);
		try {
			List<PageData> subjectList = v1Service.getTeacherSubjectInfo(pt);
			if (subjectList != null && subjectList.size() > 0) {
				return subjectList.get(0).getString("SUBJECT_ID");
			}
		}catch(Exception ex){}
		return null;
	}

	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/paper_view2")
	public ModelAndView paper_view2(Page page) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Paper");
		String userId = this.getUserID();
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("userId", userId);
		mv.setViewName("sunvote/teacher/paper_view2");
		mv.addObject("pd", pd);
		return mv;
	}
	
	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/paper_view1")
	public ModelAndView paper_view1(Page page) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Paper");
		String userId = this.getUserID();
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("userId", userId);
		mv.setViewName("sunvote/teacher/paper_view1");
		mv.addObject("pd", pd);
		return mv;
	}
	
	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/classansync")
	public ModelAndView classansync(Page page) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Paper");
		String userId = this.getUserID();
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("userId", userId);
		if(pd.get("TEST_ID") == null){
			pd.put("TEST_ID", pd.get("TESTPAPERID"));
		}
		List<PageData> diffcultClassList = teacherService.diffcultClassReport(pd);
		for(PageData diffcultPd : diffcultClassList){
			double rightNum = Double.parseDouble(diffcultPd.getString("RIGHT_NUM"));
			double allNum = Double.parseDouble(diffcultPd.getString("ALL_NUM"));
			double persent = rightNum * 100.0 / allNum ;
			diffcultPd.put("RIGHT_PERSENT", String.format("%.2f", persent));
		}
		
		List<PageData> diffcultStudentList = teacherService.diffcultStudentReport(pd);
		for(PageData diffcultPd : diffcultStudentList){
			double rightNum = Double.parseDouble(diffcultPd.getString("RIGHT_NUM"));
			double allNum = Double.parseDouble(diffcultPd.getString("ALL_NUM"));
			double persent = rightNum * 100.0 / allNum ;
			diffcultPd.put("RIGHT_PERSENT", String.format("%.2f", persent));
		}
		
		List<PageData> knowadgeClassList = teacherService.knowadgeClassReport(pd);
		for(PageData diffcultPd : knowadgeClassList){
			double rightNum = Double.parseDouble(diffcultPd.getString("RIGHT_NUM"));
			double allNum = Double.parseDouble(diffcultPd.getString("ALL_NUM"));
			double persent = rightNum * 100.0 / allNum ;
			diffcultPd.put("RIGHT_PERSENT", String.format("%.2f", persent));
		}
		
		List<PageData> knowadgeStudentList = teacherService.knowadgeStudentReport(pd);
		for(PageData diffcultPd : knowadgeStudentList){
			double rightNum = Double.parseDouble(diffcultPd.getString("RIGHT_NUM"));
			double allNum = Double.parseDouble(diffcultPd.getString("ALL_NUM"));
			double persent = rightNum * 100.0 / allNum ;
			diffcultPd.put("RIGHT_PERSENT", String.format("%.2f", persent));
		}
		mv.addObject("diffcultClassList", diffcultClassList);
		mv.addObject("diffcultClassListSize", diffcultClassList.size());
		mv.addObject("diffcultStudentList", diffcultStudentList);
		mv.addObject("knowadgeClassList", knowadgeClassList);
		mv.addObject("knowadgeClassListSize", knowadgeClassList.size());
		mv.addObject("knowadgeStudentList", knowadgeStudentList);
		
		mv.setViewName("sunvote/teacher/paper_report");
		mv.addObject("pd", pd);
		return mv;
	}
	
	
	

	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/set_question")
	public ModelAndView set_question(Page page) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Paper");
		ModelAndView mv = this.getModelAndView();
		String userId = this.getUserID();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("userId", userId);
		mv.setViewName("sunvote/teacher/set_question");
		mv.addObject("pd", pd);
		return mv;
	}

	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/list")
	public ModelAndView list(Page page) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Teacher");
		// if(!Jurisdiction.buttonJurisdiction(menuUrl, "cha")){return null;}
		// //校验权限(无权查看时页面会有提示,如果不注释掉这句代码就无法进入列表页面,所以根据情况是否加入本句代码)
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		String keywords = pd.getString("keywords"); // 关键词检索条件
		if (null != keywords && !"".equals(keywords)) {
			pd.put("keywords", keywords.trim());
		}
		page.setPd(pd);
		List<PageData> varList = teacherService.list(page); // 列出Teacher列表
		mv.setViewName("sunvote/teacher/teacher_list");
		mv.addObject("varList", varList);

		List<PageData> schools = schoolService.listAll(pd);
		mv.addObject("schools", schools);

		mv.addObject("pd", pd);
		mv.addObject("QX", Jurisdiction.getHC()); // 按钮权限
		return mv;
	}
	
	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/listcs")
	public ModelAndView listcs(Page page) throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Teacher");
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		page.setPd(pd);
		List<PageData> varList = teacherService.list(page); // 列出Teacher列表
		mv.setViewName("sunvote/teacher/teacher_list2");
		mv.addObject("varList", varList);
		
		mv.addObject("pd", pd);
		return mv;
	}
	
	/**
	 * 列表
	 * 
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value = "/index")
	public ModelAndView index() throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "列表Teacher");
		// if(!Jurisdiction.buttonJurisdiction(menuUrl, "cha")){return null;}
		// //校验权限(无权查看时页面会有提示,如果不注释掉这句代码就无法进入列表页面,所以根据情况是否加入本句代码)
		ModelAndView mv = this.getModelAndView();
		mv.setViewName("sunvote/teacher/indexPage");
		mv.addObject("pd", this.getPageData());
		return mv;
	}

	/**
	 * 去新增页面
	 * 
	 * @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/teacher/teacher_edit");

		List<PageData> schools = schoolService.listAll(pd);
		mv.addObject("schools", schools);

		mv.addObject("msg", "save");
		mv.addObject("pd", pd);
		return mv;
	}

	/**
	 * 去修改页面
	 * 
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/goEdit")
	public ModelAndView goEdit() throws Exception {
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = teacherService.findById(pd); // 根据ID读取
		mv.setViewName("sunvote/teacher/teacher_edit");
		List<PageData> schools = schoolService.listAll(pd);
		mv.addObject("schools", schools);
		mv.addObject("msg", "edit");
		mv.addObject("pd", pd);
		return mv;
	}

	/**
	 * 批量删除
	 * 
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/deleteAll")
	@ResponseBody
	public Object deleteAll() throws Exception {
		logBefore(logger, Jurisdiction.getUsername() + "批量删除Teacher");
		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(",");
			teacherService.deleteAll(ArrayDATA_IDS);
			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() + "导出Teacher到excel");
		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("科目列表"); // 9
		titles.add("教师卡编号"); // 10
		dataMap.put("titles", titles);
		List<PageData> varOList = teacherService.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).get("SCHOOL_ID").toString()); // 1
			vpd.put("var2", varOList.get(i).getString("NAME")); // 2
			vpd.put("var3", varOList.get(i).getString("PHONE")); // 3
			vpd.put("var4", varOList.get(i).getString("SEAT_PHONE")); // 4
			vpd.put("var5", varOList.get(i).getString("CARD_NO")); // 5
			vpd.put("var6", varOList.get(i).getString("ACCOUT")); // 6
			vpd.put("var7", varOList.get(i).getString("PASSWORD")); // 7
			vpd.put("var8", varOList.get(i).get("SEX").toString()); // 8
			vpd.put("var9", varOList.get(i).getString("SUBJECT_IDS")); // 9
			vpd.put("var10", varOList.get(i).getString("KEYPAD_ID")); // 10
			varList.add(vpd);
		}
		dataMap.put("varList", varList);
		ObjectExcelView erv = new ObjectExcelView();
		mv = new ModelAndView(erv, dataMap);
		return mv;
	}

	@InitBinder
	public void initBinder(WebDataBinder binder) {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		binder.registerCustomEditor(Date.class, new CustomDateEditor(format,
				true));
	}

	/**
	 * 批量删除
	 * 
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/info", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Object info() throws Exception {
		PageData pd = this.getPageData();
		ResponseGson<PageData> res = new ResponseGson();
		pd.put("ID", this.geTeacherID());
		PageData pageData = teacherService.findById(pd);
		if (pageData != null && pageData.getString("ID") != null) {
			pageData.put("PASSWORD", "");// 返回参数中不返回密码
			PageData pt = new PageData();
			pt.put("TEACHER_ID", pageData.get("ID"));
			// 在任课表中查找老师教哪些班级,然后查出班级信息
			List<PageData> classInfoList = v1Service
					.getTeacherClassInfo(pt);
			
			pageData.put("classInfoList", classInfoList);
			// 在认可表中查找老师教哪些科目,然后查出科目信息
			List<PageData> subjectList = v1Service
					.getTeacherSubjectInfo(pt);
			// 一个sql语句完成。
			pageData.put("subjectList", subjectList);
			
			pageData.remove("SUBJECT_IDS");
			
			PageData eventPd = new PageData();
			eventPd.put("EVENT_ID", get32UUID());
			eventPd.put("EVENT_NAME", "login");
			eventPd.put("EVENT_USER", pageData.getString("ID"));
			eventPd.put("EVENT_TYPE", "0");
			eventPd.put("EVENT_START_TIME", Tools.date2Str(new Date()));
			if (pd.getString("CLIENT_ID") != null) {
				eventPd.put("CLIENT_ID", pd.getString("CLIENT_ID"));
			} else {
				eventPd.put("CLIENT_ID", "CLIENT");
			}
			res.setData(pageData);
			// 填充数据到返回数据中
		} else {
			res.set1Error();
		}
		
		return res.toJson();
	}
	
	

}