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";
}
}
最近下载更多
xiaohuaidan455 LV2
2月21日
朱俪的邮件及存储 LV8
2023年4月28日
泓鼎168 LV20
2023年3月30日
wanglinddad LV55
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日

最近浏览