package cn.edu.management.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import cn.edu.management.comm.ApplyTeacherComparator;
import cn.edu.management.comm.DateConventer;
import cn.edu.management.comm.FileManage;
import cn.edu.management.comm.Page;
import cn.edu.management.comm.VOconver;
import cn.edu.management.comm.disAuditGraduationResultComparator;
import cn.edu.management.service.ManagerService;
import cn.edu.management.service.TeacherService;
import cn.edu.management.service.UserService;
import cn.edu.management.vo.showVO.EMS_GraduationA;
import cn.edu.management.vo.showVO.GraduationStudentInfor;
import cn.edu.management.vo.showVO.ShowMessageVO;
import cn.edu.management.vo.showVO.StudentGraduationWorksMange;
import cn.edu.management.vo.showVO.disAuditGraduationResult;
import cn.edu.management.vo.showVO.disAuditGraduationTitle;
import cn.edu.management.vo.showVO.showApplyModifyLogVO;
import cn.edu.management.vo.showVO.studentGradeSearch;
import cn.edu.management.vo.voImpl.ApplyModifyLogVO;
import cn.edu.management.vo.voImpl.ClassTypeVO;
import cn.edu.management.vo.voImpl.EMS_Class;
import cn.edu.management.vo.voImpl.EMS_CourseRecord;
import cn.edu.management.vo.voImpl.EMS_GraduateGrade;
import cn.edu.management.vo.voImpl.EMS_Graduation;
import cn.edu.management.vo.voImpl.Ems_Student_VO;
import cn.edu.management.vo.voImpl.Ems_Teacher_VO;
import cn.edu.management.vo.voImpl.MessageVO;
import cn.edu.management.vo.voImpl.ProfessionVO;
import com.opensymphony.xwork2.ActionSupport;
@Component
@Scope("prototype")
public class TeacherAction extends ActionSupport {
private List<EMS_GraduationA> graduateaList;//方便界面显示
private List<showApplyModifyLogVO> applyModifyList;//申请信息记录表
private List<ProfessionVO> professionList;//专业
private List<Ems_Teacher_VO> teacherList ;//教师
private List<GraduationStudentInfor> ggStudentInforList;//毕业设计学生信息界面类
private List<StudentGraduationWorksMange> StudentGraduationWorksMange;//毕业设计学生信息界面类
private List<studentGradeSearch> studentGradeSearchList;//毕业设计学生信息界面类
private List<disAuditGraduationTitle> disAuditGraTit;//显示学生毕业设计申请题目
private List<disAuditGraduationResult> disAuditGraResult;//显示学生毕业设计审核结果
//private List<InputGraduationGrade> disInputGraduationGrade;//显示录入毕业设计成绩界面类
private List<ShowMessageVO> disMessageVO;//显示已回复留言
private List<ClassTypeVO> courseTypeLit;
private String[] fileList; //显示文件列表使用
/**上传文件的接收类型,名字要与表单相应元素的name属性值*/
private File image;
/**上传文件的名字,必须为表单的name加上FileName字符串*/
private String imageFileName;
private TeacherService teacherService;
private UserService userService;
private ManagerService managerService;
@Resource
public void setTeacherService(TeacherService teacherService) {
this.teacherService = teacherService;
}
@Resource
public void setUserService(UserService userService) {
this.userService = userService;
}
@Resource
public void setManagerService(ManagerService managerService) {
this.managerService = managerService;
}
/**
* 局部刷新验证毕业设计名称是否存在
* @return
* @throws IOException
*/
public void checkGname() throws IOException {
HttpServletRequest request = ServletActionContext.getRequest();
String account = request.getParameter("account");
HttpServletResponse response = ServletActionContext.getResponse();
try {
response.setCharacterEncoding("utf-8");
if(account.equals("")||account==null)
response.getWriter().print("{\"result\":\"space\"}");
else
{
boolean flag = this.teacherService.checkGname(account);
System.out.println("flag:"+flag);
if(flag)
{
response.getWriter().print("{\"result\":\"true\"}");
}
else
{
response.getWriter().print("{\"result\":\"false\"}");
}
}
} catch(Exception e) {
String msg = "{result:false,desc:\"失败\"}";
response.setCharacterEncoding("utf-8");
response.getWriter().print(msg);
}
}
/******************************************个人信息维护***********************************************/
/*****查看个人信息*****/
public String displayPersonInformation() {
System.out
.println("=========TeacherAction==========displayPersonInformation===========");
HttpServletRequest request = ServletActionContext.getRequest();
//从request中得到session
HttpSession session = request.getSession();
String idnum = (String)session.getAttribute("teacheridnum");/////////
System.out.println("得到的编号:"+idnum);
Ems_Teacher_VO vo = (Ems_Teacher_VO) this.teacherService.displayPersonInformation(idnum);
String profession = vo.getProfession().getPro_name();
request.setAttribute("profession", profession);
request.setAttribute("teacherVO", vo);
//因为在显示时没有密码,方便修改时使用
session.setAttribute("pwd", vo.getPassword());
return "PersonInformationQuery";
}
/**
* update 教师查看个人信息修改地址按钮实现
* @return
*/
public String updateTeacherPersonInfor(){
System.out.println("====teacheraction====updateTeacherPersonInfor=======");
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
String idnum = request.getParameter("idnum");
String address = request.getParameter("address");
String password = (String)session.getAttribute("pwd");
String name = request.getParameter("name");
String sex = request.getParameter("sex");
String idcard = request.getParameter("idcard");
String nation = request.getParameter("nation");
String scientific = request.getParameter("scientific");
String title = request.getParameter("title");
Ems_Teacher_VO teacherVO = this.managerService.getModifyTeacherInfo(idnum);
teacherVO.setSex(sex);
teacherVO.setAddress(address);
request.setAttribute("teacherVO", teacherVO);//方便界面显示修改的
this.teacherService.update( teacherVO);
return "updateTeacherPersonInfor";
}
/**
*
*修改密码
* @return
*/
public String updateTeacherPassword() {
System.out.println("====teacheraction====updateTeacherPassword=======");
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
Ems_Teacher_VO teacherVO = new Ems_Teacher_VO();
String userId = (String)session.getAttribute("teacheridnum");
String password = request.getParameter("prePassword");
String newpwd = request.getParameter("newPassword");
teacherVO.setIdnum( userId );
teacherVO.setPassword( password );
teacherVO = this.userService.validate_teacher( teacherVO );
if( null == teacherVO ){
request.setAttribute("msg", "wrong");//用于旧密码不正确
return "prePasswordWorng";
}else{
//从数据库中取出这个编�