package com.wy.action;
import java.util.List;
import java.util.Map;
import org.apache.struts2.interceptor.RequestAware;
import com.wy.dao.ObjectDao;
import com.wy.entity.EmployeeForm;
import com.wy.entity.InviteJobForm;
import com.wy.tool.GetAutoNumber;
public class EmployeeAction implements RequestAware {
private int departmentId;
private String em_serialNumber;
private EmployeeForm employeeForm;
private ObjectDao objectDao;
private Map<String, Object> request;
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
// 员工录用
public String addEmployee() {
objectDao.insertObjectForm(employeeForm);
return "operationEmployee";
}
// 删除员工信息
public String deleteEmployee() {
String condition = "from EmployeeForm em where em.em_serialNumber='"
+ em_serialNumber + "'";
employeeForm = (EmployeeForm) objectDao.getObjectForm(condition);
if (!objectDao.deleteObjectForm(employeeForm)) {
request.put("result", "删除员工信息失败,可能还存在其他的信息");
}
request.put("result", "删除员工成功");
return "operationEmployee";
}
// 转向员工录用的页面
public String forwardEmploye() {
String condition = "from EmployeeForm order by id desc";
List list = objectDao.getObjectList(condition);
String autoNumber = "1";
if (list.size() != 0) {
EmployeeForm employeeform = (EmployeeForm) list.get(0);
Integer em_serialNumber = Integer.valueOf(employeeform.getId()) + 1;
autoNumber = String.valueOf(em_serialNumber);
}
autoNumber = GetAutoNumber.getMaxNuber(autoNumber);
request.put("departmentList", objectDao
.getObjectList("from DepartmentForm"));
InviteJobForm inviteJobForm = (InviteJobForm) objectDao
.getObjectForm("from InviteJobForm where id='" + id + "'");
employeeForm = new EmployeeForm();
employeeForm.setEm_serialNumber(autoNumber);// 将员工编号自动赋值
employeeForm.setEm_name(inviteJobForm.getName());// 将员工姓名赋值
employeeForm.setEm_afterschool(inviteJobForm.getAfterSchool());// 将员工的毕业学校自动赋值
employeeForm.setEm_sex(inviteJobForm.getSex());// 将员工的性别赋值
employeeForm.setEm_born(inviteJobForm.getBorn());// 将员工的出生日期赋值
employeeForm.setEm_address(inviteJobForm.getAddress());// 将员工地址赋值
employeeForm.setEm_culture(inviteJobForm.getTeachSchool());// 将员工的文化程度赋值
employeeForm.setEm_tel(inviteJobForm.getTel());// 将员工电话赋值
employeeForm.setEm_speciality(inviteJobForm.getSpecialty());// 将员工所学专业赋值
request.put("employeeForm", employeeForm);
request.put("id", id);
return "forwardEmploy";
}
// 转向添加员工的页面
public String forwardInsertEmployee() {
String condition = "from EmployeeForm order by id desc";
List list = objectDao.getObjectList(condition);
String autoNumber = "1";
if (list.size() != 0) {
EmployeeForm employeeform = (EmployeeForm) list.get(0);
Integer em_serialNumber = Integer.valueOf(employeeform.getId()) + 1;
autoNumber = String.valueOf(em_serialNumber);
}
autoNumber = GetAutoNumber.getMaxNuber(autoNumber);
request.put("autoNumber", autoNumber);
request.put("departmentList", objectDao
.getObjectList("from DepartmentForm"));
return "forwardInsertEmployee";
}
// 转向修改员工的页面
public String forwardUpdateEmployee() {
System.out.println(em_serialNumber);
String condition = "from EmployeeForm em where em.em_serialNumber='"
+ em_serialNumber + "'";
this.setEmployeeForm((EmployeeForm) objectDao.getObjectForm(condition));
System.out.println(employeeForm.getEm_name());
System.out.println("sex:" + employeeForm.getEm_sex());
request.put("departmentList", objectDao
.getObjectList("from DepartmentForm"));
return "forwardUpdateEmployee";
}
public int getDepartmentId() {
return departmentId;
}
public String getEm_serialNumber() {
return em_serialNumber;
}
public EmployeeForm getEmployeeForm() {
return employeeForm;
}
public ObjectDao getObjectDao() {
return objectDao;
}
// 员工查看操作
public String queryEmployee() {
List list = null;
String condition = "from EmployeeForm order by id desc";
if (employeeForm == null && departmentId != 0) {
System.out.println(departmentId);
condition = "from EmployeeForm where em_departmentId='"
+ departmentId + "' order by id desc";
request.put("departmentId", departmentId);
}
list = objectDao.getObjectList(condition);
request.put("list", list);
request.put("departmentList", objectDao
.getObjectList("from DepartmentForm"));
return "queryEmployee";
}
// 员工查看详细信息操作
public String queryOneEmployee() {
System.out.println(em_serialNumber);
String condition = "from EmployeeForm where em_serialNumber='"
+ em_serialNumber + "'";
EmployeeForm employeeForm = (EmployeeForm) objectDao
.getObjectForm(condition);
request.put("employeeForm", employeeForm);
request.put("departmentList", objectDao
.getObjectList("from DepartmentForm"));
return "queryOneEmployee";
}
// 添加员工
public String saveEmployee() {
objectDao.insertObjectForm(employeeForm);
return queryEmployee();
}
public void setDepartmentId(int departmentId) {
this.departmentId = departmentId;
}
public void setEm_serialNumber(String em_serialNumber) {
this.em_serialNumber = em_serialNumber;
}
public void setEmployeeForm(EmployeeForm employeeForm) {
this.employeeForm = employeeForm;
}
public void setObjectDao(ObjectDao objectDao) {
this.objectDao = objectDao;
}
public void setRequest(Map<String, Object> request) {
this.request = request;
}
// 修改员工
public String updateEmployee() {
System.out.println(employeeForm.getId());
System.out.println(employeeForm.getEm_name());
objectDao.updateObjectForm(employeeForm);
this.employeeForm = null;
return queryEmployee();
}
}
- 1
- 2
前往页