首页>代码>S2SH开发的企业办公OA管理系统>/OA/src/com/oa/action/DepartmentAction.java
package com.oa.action;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.oa.base.BaseAction;
import com.oa.domain.Department;
import com.oa.utils.DepartmentUtils;
import com.opensymphony.xwork2.ActionContext;
@Controller
@Scope("prototype")
public class DepartmentAction extends BaseAction<Department>{
	private static final long serialVersionUID = 1L;
	private Long parentId;
	public Long getParentId() {
		return parentId;
	}
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}
	/**
	 * 列表功能
	 * @return
	 * @throws Exception
	 */
	public String list() throws Exception{
		List<Department> departmentList = null;
		
//		 列表显示,根据parentId判断显示的是哪层的部门
		 
		if (parentId == null) {//顶级部门
			departmentList = departmentService.findTopList();
		} else {//子部门列表
			departmentList = departmentService.findChildrenList(parentId);
			
			Department parent = departmentService.findById(parentId);
			ActionContext.getContext().put("parent", parent);
		}
		ActionContext.getContext().put("departmentList", departmentList);
		return "list";
	}
	/**
	 * 删除功能
	 * @return
	 * @throws Exception
	 */
	public String delete() throws Exception{
		departmentService.remove(model.getId());
		return "toList";
	} 
	/**
	 * 添加页面
	 * @return
	 * @throws Exception
	 */
	public String addUI() throws Exception{
		//准备数据,departmentList  准备上级部门数据
		List<Department> topList = departmentService.findTopList();
		List<Department> departmentList = DepartmentUtils.getAllDepartments(topList);
		ActionContext.getContext().put("departmentList", departmentList);
		
		return "saveUI";
	}
	/**
	 * 添加功能
	 * @return
	 * @throws Exception
	 */
	public String add() throws Exception{
		//封装信息到对象中   上级部门信息
		Department parent = departmentService.findById(parentId);
		model.setParent(parent);
		
		//保存
		departmentService.save(model);
		return "toList";
	}
	/**
	 * 修改页面
	 * @return
	 * @throws Exception
	 */
	public String updateUI() throws Exception{
		//准备数据,departmentList  准备上级部门数据
		List<Department> topList = departmentService.findTopList();
		List<Department> departmentList = DepartmentUtils.getAllDepartments(topList);
		ActionContext.getContext().put("departmentList", departmentList);
		//准备回显的数据
		Department department = departmentService.findById(model.getId());
		ActionContext.getContext().getValueStack().push(department);
		
		if (department.getParent() != null) {
			parentId = department.getParent().getId();
		}
		return "saveUI";
	}
	/**
	 * 修改功能
	 * @return
	 * @throws Exception
	 */
	public String update() throws Exception{
		//从数据库中查询出原来的数据
		Department department = departmentService.findById(model.getId());
		//设置要更改的属性
		department.setName(model.getName());
		department.setDescription(model.getDescription());
		//设置所属的上级部门
		department.setParent(departmentService.findById(parentId));
		//将更改后的对象数据存储到数据库中
		departmentService.modify(department);
		return "toList";
	}
}
最近下载更多
朱俪的邮件及存储  LV8 2023年4月28日
泓鼎168  LV19 2023年3月30日
wanglinddad  LV54 2022年5月26日
529948627  LV6 2022年3月14日
蛇蛇皮怪  LV14 2022年3月8日
微信网友_5845420553359360  LV4 2022年2月25日
juanito8396  LV6 2021年12月20日
and123456  LV11 2021年5月11日
shiyujir  LV7 2021年4月8日
tttxin  LV11 2020年9月21日
最近浏览更多
yangyuer  LV1 昨天
m5433661  LV2 3月28日
jay1992  LV14 3月16日
pangzhihui  LV12 3月1日
氟西汀来救你  LV2 1月10日
WBelong  LV7 2023年12月25日
季明亮 2023年11月21日
暂无贡献等级
fesfefe  LV13 2023年10月30日
Weishenghui  LV7 2023年10月20日
molu123456 2023年10月16日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友