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

📄 c431controller.java

📁 使用spring ,hibernate 框架的稽查管理系统
💻 JAVA
字号:
package com.je.ims.controller.c431;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

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

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.chttl.im.organization.Person;
import com.chttl.im.organization.UnitHistoryBean;
import com.je.ims.dao.C431FoundProceedingDAO;
import com.je.ims.dao.C431NoOpinionDAO;
import com.je.ims.dao.C431NotionDAO;
import com.je.ims.dao.C84TeamDAO;
import com.je.ims.dao.C851RoleDao;
import com.je.ims.hibernate.FoundProceeding;
import com.je.ims.hibernate.FoundProceedingId;
import com.je.ims.hibernate.Notion;
import com.je.ims.hibernate.RoleId;
import com.je.ims.hibernate.Role;
import com.je.ims.hibernate.Team;
import com.je.ims.util.MenuUtils;
//import com.je.ims.util.StringTool;

public class C431Controller implements Controller {

	private C431NoOpinionDAO dao;   //有關無意見處理的DAO
    private C851RoleDao roledao;    //有關角色的DAO
    private C84TeamDAO teamdao;     //有關組別的DAO
    private C431NotionDAO notiondao;
    private C431FoundProceedingDAO foundProceedingDAO;
    
    public void setFoundProceedingDAO(C431FoundProceedingDAO dao)
    {
    	this.foundProceedingDAO = dao;
    }
    public C431FoundProceedingDAO getFoundProceedingDAO()
    {
    	return foundProceedingDAO;
    }
	public void setDao(C431NoOpinionDAO dao)
	{
		this.dao = dao;
	}
	public C431NoOpinionDAO getDao()
	{
		return dao;
	}
	
	public void setNotiondao(C431NotionDAO dao)
	{
		this.notiondao = dao;
	}
	public C431NotionDAO getNotiondao()
	{
		return notiondao;
	}
	
	public void setRoledao(C851RoleDao roledao)
	{
		this.roledao = roledao;
	}
	public C851RoleDao getRoledao()
	{
		return roledao;
	}
	
	public void setTeamdao(C84TeamDAO teamdao)
	{
		this.teamdao = teamdao;
	}
	public C84TeamDAO getTeamdao()
	{
		return teamdao;
	}
	
	
	public ModelAndView handleRequest(HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		String actionType=req.getParameter("actionType");
		ModelAndView model=null;
		//如果.do後參數為空,即c431.do
		if(actionType!=null)// if 1
		{
			//如果不進入設定無意見專案頁面時,執行以下過程
			if(actionType.equals("noOpinion"))
			{
				return new ModelAndView("c431noOpinion.jsp",null);
			}
			//進入整個作業意見主頁面時,則執行以下過程
			if(actionType.equals("opinion"))
				return new ModelAndView("c431.jsp",null);
			//進入選擇部門/單位彈出視窗時,則執行以下過程
			if(actionType.equals("selectApart"))
			{
				model = handleSelectApart(req,res);
				if(model!=null)
				return model;
				else
				return new ModelAndView("c431apartmentSelect.jsp",null);
			}
			//提交設置的作業無意見信息時,則執行以下過程
			if(actionType.equals("noOpinionCommit"))
			{
				model = noOpinionCommit(req,res);
				if(model!=null)
				return model;
				else
				return new ModelAndView("c431.do?actionType=opinion",null);
			}
			//進入增加作業意見頁面
			if(actionType.equals("add"))
			{
				model = handleAdd(req,res);
				return model;
			}
			//提交增加意見
			if(actionType.equals("doAdd"))
			{
				model = handleDoAdd(req,res);
				return model;
			}
		}//end of if 1
		return new ModelAndView("c431select.jsp",null);
	}
	
	
	public ModelAndView handleSelectApart(HttpServletRequest request,
			HttpServletResponse response) throws Exception
	{   
		Map model=new HashMap();
		String y = request.getParameter("year");
		Integer yy = Integer.valueOf(y);
		int year = yy.intValue();
		year = 2006;  // for  test setting
		UnitHistoryBean  unitBean = new UnitHistoryBean ();
		unitBean.setYear(year);
		HttpSession session=request.getSession();
		//Person person = (Person) session.getAttribute("person");
		//get RoleId
		LinkedList list=(LinkedList)session.getAttribute("menu");
		List roleList=(List)MenuUtils.getRole(list,"c431.do");
		RoleId id=(RoleId)roleList.get(0); //RoleId get
		Long roleTypeId = id.getRoleTypeId();
	    String roleId = id.getRoleId();
	    Role role = roledao.findRole(roleTypeId,roleId);
	    String orgId = role.getOrgId() ;
	    String orgName = role.getOrgName();
		if(orgId!=null)
		{
			//Vector apartments = unitBean.getOrgDataOrderByMainOrg();
			Vector apartments = unitBean.getAllSubUnits(orgId);
			model.put("apartments",apartments);
			//model.put("orgId",orgId);
			return new ModelAndView("c431apartmentSelect.jsp",model);
		}
		else
		{
			Vector apartments = unitBean.getOrgDataOrderByMainOrg();
			model.put("apartments",apartments);
			//model.put("orgId",orgId);			
			return new ModelAndView("c431apartmentSelect.jsp",model);
		}
		//return null;
	}
	
	
	public ModelAndView noOpinionCommit(HttpServletRequest request,
			HttpServletResponse response) throws Exception
	{ 
		request.setCharacterEncoding("MS950");
		HttpSession session=request.getSession();
		Person person = (Person) session.getAttribute("person");
		String editorId = person.getUserID();
		Notion notion = new Notion();
		String y = request.getParameter("year");
		String month = request.getParameter("month");
	    String refNode = request.getParameter("refNode");
	    String apartment = request.getParameter("apartment");
	    String level = request.getParameter("level");
	    String writer = new String(request.getParameter("writer").getBytes("ISO-8859-1"),"MS950");
	    String updateTime = request.getParameter("updateTime");
	    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d = new Date();
        updateTime = updateTime+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
        Date date = df.parse(updateTime);	    
	    Long yy = Long.valueOf(y);
	    long yyy = yy.longValue();
	    yyy+=1911;
	    notion.setYear(new Long(yyy));
	    notion.setMonth(Long.valueOf(month));
	    notion.setNodeId(refNode);
	    notion.setEditorId(editorId);
	    notion.setEditorName(writer);
	    notion.setFillDate(date);
	    notion.setOrgPk(apartment);
	    notion.setEditState(new Long(0));
	    try
	    {
	    	dao.saveNotion(notion);
	    }catch(Exception e)
	    {
	    	System.out.print(e);
	    	return null;
	    }
	    return new ModelAndView("c431saveNotion.jsp",null);		
	}
	
	
	public ModelAndView handleAdd(HttpServletRequest request,
			HttpServletResponse response) throws Exception
	{ 
		Map model=new HashMap();
		//String y = request.getParameter("year");
		//Integer yy = Integer.valueOf(y);
		//int year = yy.intValue();
		int year = 2006;  // for  test setting		
		request.setCharacterEncoding("MS950");
		HttpSession session=request.getSession();
		//Person person = (Person) session.getAttribute("person");
		//get RoleId
		LinkedList list=(LinkedList)session.getAttribute("menu");
		List roleList=(List)MenuUtils.getRole(list,"c431.do");
		RoleId id=(RoleId)roleList.get(0); //RoleId get
		Long roleTypeId = id.getRoleTypeId();
	    String roleId = id.getRoleId();
	    Role role = roledao.findRole(roleTypeId,roleId);
		//Role role = null;
		if(role!=null)
	    {
	    	Long teamPk = role.getTeamPk();
	    	//for test
	    	teamPk = new Long(64);
	    	
	    	if(teamPk!=null)
	    	{
	    		Team team = teamdao.GetObjById(teamPk);
	    		model.put("team",team);
	    		//model.put("teams",null);
	    		//System.out.print(teamPk);
	    		return new ModelAndView("c431add.jsp",model);
	    	}
	    	else
	    	{
	    		List teams = teamdao.GetAll(new Long(year));
	    		model.put("teams",teams);
	    		return new ModelAndView("c431add.jsp",model);	    		
	    	}
	    } 
		return new ModelAndView("c431add.jsp",null);	
	}	
	
	
	public Date changeDate(String found_date) throws ParseException
	{
		DateFormat df = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");	
		String temp=found_date.substring(0,3);
		int temp1=Integer.parseInt(temp);
		temp1+=1911;
		temp=temp1+found_date.substring(3);
		found_date = temp;
		Date d = new Date();
		found_date = found_date+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
		Date date = df.parse(found_date);
		return date;
	}
	
	
	public ModelAndView handleDoAdd(HttpServletRequest request,
			HttpServletResponse response) throws Exception
	{ 
		request.setCharacterEncoding("MS950");
		HttpSession session=request.getSession();
		Person person = (Person) session.getAttribute("person");
		String editorId = person.getUserID();
	    String writer = person.getUserName(); //new String(person.getUserName().getBytes("ISO-8859-1"),"MS950");
		String teamPk = request.getParameter("team");
		Long pk = new Long(teamPk);
		Team team = teamdao.GetObjById(pk);
		String teamId = team.getTeamId();
		String teamName = team.getTeamName();
		Notion notion = new Notion();
		String y = request.getParameter("year");
		String month = request.getParameter("month");
		String apartment = request.getParameter("apartment");	
		String found_date = request.getParameter("start1");
		Date date =changeDate(found_date);
	    String nodeId = request.getParameter("refNode");
	    //String nodeName = 
	    String nodeName = request.getParameter("refName");
	    Long yy = Long.valueOf(y);
	    long yyy = yy.longValue();
	    notion.setYear(new Long(yyy));
	    notion.setMonth(Long.valueOf(month));
	    notion.setNodeId(nodeId); 
	    notion.setNodeName(nodeName); 
	    notion.setTeamId(teamId);
	    notion.setTeamName(teamName);
	    notion.setEditorId(editorId);
	    notion.setEditorName(writer);
	    notion.setOrgPk(apartment);
	    notion.setFoundDate(date);
	    notion.setEditState(new Long(1));
	    notion.setAdviceState(new Long(1));
	    try
	    {
	    	dao.saveNotion(notion);
	    }catch(Exception e)
	    {
	    	System.out.print(e);
	    }
	    List notions = notiondao.getAllByDesc();
	    Notion no = (Notion)notions.get(0);
	    Long notionId = no.getNotionId();
	    Enumeration names = request.getParameterNames();
	    long item = 0;
	    while(names.hasMoreElements())  //begin of while 1
	    {
	    	String textarea = (String)names.nextElement();
	    	if(textarea.startsWith("textarea")) //begin of if1
	    	{
	    		item++;
	    		int temp1 = textarea.length()-8;
	    		boolean withFiles = false;	   
	    		Enumeration names2 = request.getParameterNames();
	    		while(names2.hasMoreElements()) //begin of while 2
	           {
	    	    	String files = (String) names2.nextElement();
	    	    	int temp2 = files.length()-5;
	    	    	if(files.startsWith("files")&&temp1==temp2) //如果 textarea 有對應的 files
	    	    	{
	    	    		withFiles = true;
	    	    		FoundProceedingId fpi = new FoundProceedingId();
	    	    		fpi.setNotionId(notionId);
	    	    		fpi.setItem(new Long(item));
	    	    		fpi.setVersion(new Long(1));
	    	    		FoundProceeding fp = new FoundProceeding();
	    	    		fp.setId(fpi);
	    	    		String content = new String(request.getParameter(textarea).getBytes("ISO-8859-1"),"MS950");
	    	    		fp.setContent(content);
	    	    		String [] attachment = request.getParameterValues(files);
	    	    		String attachments = "";
	    	    		for(int i=0;i<attachment.length;i++)
	    	    		{
	    	    			System.out.println(attachment[i]);
	    	    			attachments = attachments+attachment[i]+";";
	    	    		}
	    	    		//System.out.print(attachments);
	    	    		fp.setAttachment(attachments);
	    	    		foundProceedingDAO.saveFoundProceeding(fp);
	    	    		break;
	    	    	} //end of if2
	           } //end of while 2
	    		if(withFiles==false)//begin of if3
	    		{
	    			FoundProceedingId fpi = new FoundProceedingId();
    	    		fpi.setNotionId(notionId);
    	    		fpi.setItem(new Long(item));
    	    		fpi.setVersion(new Long(1));
    	    		FoundProceeding fp = new FoundProceeding();
    	    		fp.setId(fpi);
    	    		String content = new String(request.getParameter(textarea).getBytes("ISO-8859-1"),"MS950");
    	    		fp.setContent(content);
    	    		foundProceedingDAO.saveFoundProceeding(fp);
	    		}//end of if3
	    	
	    	}//end of if 1
	    }	    //end of while 1
	    return new ModelAndView("c431.do");		
	}
}

⌨️ 快捷键说明

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