⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taskaction.java

📁 该项目采用Struts框架
💻 JAVA
字号:
package com.cattsoft.task.action;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.cattsoft.DAOFactory.DAOFactory;
import com.cattsoft.vo.Plan;
import com.cattsoft.vo.Task;
import com.cattsoft.vo.User;

public class TaskAction extends DispatchAction {

	// 根据主管id查询其下的所有员工信息
	public ActionForward newTaskBefore(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession(false);
		int user_id = (Integer) session.getAttribute("user_id");
		List<User> list = new ArrayList<User>();
		try {
			list = DAOFactory.getTaskInstance().queryEmployeeBy(user_id);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		request.setAttribute("list", list);
		return mapping.findForward("newTaskBeforeSuccessed");
	}

	// 删除任务
	public ActionForward deleteTask(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession(false);
		String username = (String) session.getAttribute("username");

		String[] t_id = request.getParameterValues("t_id");
		if (t_id == null || t_id.equals("")) {
			List<Task> list = new ArrayList<Task>();
			try {
				list = DAOFactory.getTaskInstance().queryAllTask(username);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.setAttribute("list", list);
			request.setAttribute("error", "请选择要删除的任务");
			return mapping.findForward("deleteTaskFailed");
		}
		for (int i = 0; i < t_id.length; i++) {
			int task_id = Integer.parseInt(t_id[i]);
			Task task = new Task();
			task.setT_id(task_id);
			try {
				DAOFactory.getTaskInstance().deleteTask(task_id);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		List<Task> list = new ArrayList<Task>();
		try {
			list = DAOFactory.getTaskInstance().queryAllTask(username);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		return mapping.findForward("deleteTaskSuccessed");
	}

	// 查看任务
	public ActionForward taskView(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession(false);
		String username = (String) session.getAttribute("username");
		List<Task> list = new ArrayList<Task>();
		try {
			list = DAOFactory.getTaskInstance().queryAllTask(username);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		return mapping.findForward("deleteTaskSuccessed");
	}

	// 根据任务id查看任务详细信息和对应的计划信息
	public ActionForward taskDetailed(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		int t_id = Integer.parseInt(request.getParameter("t_id"));
		List<Task> list = new ArrayList<Task>();
		try {
			list = DAOFactory.getTaskInstance().queryTaskBy(t_id);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		List<Plan> list1 = new ArrayList<Plan>();
		try {
			list1 = DAOFactory.getTaskInstance().queryPlanBy(t_id);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		request.setAttribute("list1",list1);
		return mapping.findForward("taskDetailedSuccessed");
	}
	
	//根据计划id查询其对应的计划详细信息
	public ActionForward planDetailed(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String planId = request.getParameter("p_id");
		if(planId ==null || planId.equals("")){
			int t_id = Integer.parseInt(request.getParameter("t_id"));
			List<Task> list = new ArrayList<Task>();
			try {
				list = DAOFactory.getTaskInstance().queryTaskBy(t_id);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			List<Plan> list1 = new ArrayList<Plan>();
			try {
				list1 = DAOFactory.getTaskInstance().queryPlanBy(t_id);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.setAttribute("list", list);
			request.setAttribute("list1",list1);
			request.setAttribute("error","请选择一个计划!");
			return mapping.findForward("taskDetailedSuccessed");
		}
		int p_id = Integer.parseInt(planId);
		List<Plan> list = new ArrayList<Plan>();
		try {
			list = DAOFactory.getTaskInstance().queryPlan(p_id);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list",list);
		return mapping.findForward("planDetailedSuccessed");
	}

	// 查询未实施状态的所有任务信息
	public ActionForward taskUndone(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession(false);
		String username = (String) session.getAttribute("username");
		List<Task> list = new ArrayList<Task>();
		try {
			list = DAOFactory.getTaskInstance().queryTaskUndoBy(username);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		if (list.size()!=0) {
			request.setAttribute("list", list);
		} else {
			request.setAttribute("error", "没有未实施的任务!");			
		}
		return mapping.findForward("taskUndone");
	}

	// 删除未实施的任务
	public ActionForward deleteTaskUndo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession(false);
		String username = (String) session.getAttribute("username");
		String[] t_id = request.getParameterValues("t_id");
		if (t_id == null || t_id.equals("")) {
			List<Task> list = new ArrayList<Task>();
			try {
				list = DAOFactory.getTaskInstance().queryTaskUndoBy(username);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.setAttribute("list", list);
			request.setAttribute("error", "请选择要删除的任务");
			return mapping.findForward("taskUndone");
		}
		for (int i = 0; i < t_id.length; i++) {
			int task_id = Integer.parseInt(t_id[i]);
			try {
				DAOFactory.getTaskInstance().deleteTask(task_id);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		List<Task> list = new ArrayList<Task>();
		try {
			list = DAOFactory.getTaskInstance().queryTaskUndoBy(username);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		return mapping.findForward("taskUndone");
	}

	// 根据未实施任务id查询任务信息显示到调整任务页面
	public ActionForward adjustTask(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		int t_id = Integer.parseInt(request.getParameter("t_id"));
		List<Task> list = new ArrayList<Task>();
		try {
			list = DAOFactory.getTaskInstance().queryTaskBy(t_id);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		return mapping.findForward("adjustTask");
	}

	// 根据主管id查询其下的所有员工信息
	public ActionForward employeeView(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession(false);
		int user_id = (Integer) session.getAttribute("user_id");
		List<User> list = new ArrayList<User>();
		try {
			list = DAOFactory.getTaskInstance().queryEmployeeBy(user_id);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		if (list.size()!=0) {
			request.setAttribute("list", list);			
		} else {
			request.setAttribute("error", "您手下目前没有员工!");
		}
		return mapping.findForward("employeeViewSuccessed");
	}

	// 根据员工id查询其详细信息
	public ActionForward employeeDetailed(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String empId = request.getParameter("emp_id");
		if(empId ==null || empId.equals("")){
			HttpSession session = request.getSession(false);
			int user_id = (Integer) session.getAttribute("user_id");
			List<User> list = new ArrayList<User>();
			try {
				list = DAOFactory.getTaskInstance().queryEmployeeBy(user_id);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.setAttribute("error","请选择一名员工!");
			request.setAttribute("list", list);
			return mapping.findForward("employeeViewSuccessed");
		}
		int user_id = Integer.parseInt(empId);		
		List<User> list = new ArrayList<User>();
		try {
			list = DAOFactory.getTaskInstance().queryEmpInfoBy(user_id);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		return mapping.findForward("employeeDetailedSuccessed");
	}
	
	//根据反馈信息更新任务状态,然后返回到查看任务页面
	public ActionForward updateTask(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		int task_id = Integer.parseInt(request.getParameter("t_id"));
		String task_state = request.getParameter("t_state");
		try {
			DAOFactory.getTaskInstance().updateTask(task_id, task_state);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		HttpSession session = request.getSession(false);
		String username = (String) session.getAttribute("username");
		List<Task> list = new ArrayList<Task>();
		try {
			list = DAOFactory.getTaskInstance().queryInForceTask(username);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		return mapping.findForward("updateTask");
	}
	
	// 查询实施中状态的所有任务信息
	public ActionForward chaseTask(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession(false);
		String username = (String) session.getAttribute("username");
		List<Task> list = new ArrayList<Task>();
		try {
			list = DAOFactory.getTaskInstance().queryInForceTask(username);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		if (list.size()!=0) {
			request.setAttribute("list", list);
		} else {
			request.setAttribute("error", "没有实施中的任务!");			
		}
		return mapping.findForward("chaseTask");
	}
	
	//根据实施中任务id查询任务和计划详细信息显示到"chasePlanInfo.jsp"页面
	public ActionForward chaseTaskDetailed(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String taskId = request.getParameter("t_id");
		if(taskId == null || taskId.equals("")){
			HttpSession session = request.getSession(false);
			String username = (String) session.getAttribute("username");
			List<Task> list = new ArrayList<Task>();
			try {
				list = DAOFactory.getTaskInstance().queryInForceTask(username);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.setAttribute("error", "请选择一个任务!");
			request.setAttribute("list", list);
			return mapping.findForward("chaseTask");
		}
		int t_id = Integer.parseInt(taskId);
		List<Task> list = new ArrayList<Task>();
		try {
			list = DAOFactory.getTaskInstance().queryTask(t_id);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		List<Plan> list1 = new ArrayList<Plan>();
		try {
			list1 = DAOFactory.getTaskInstance().queryPlanAll(t_id);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		request.setAttribute("list1",list1);
		return mapping.findForward("chaseTaskDetailed");
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -