package com.oa.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.oa.emaildao.RoleDAO;
import com.oa.model.Persimissions;
import com.oa.model.Role;
import com.oa.model.Role_Per;
import com.oa.model.Staff;
import com.oa.service.PersimissionsService;
import com.oa.service.RoleService;
import com.oa.service.StaffService;
import com.oa.util.Pager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
@Controller
@Scope("prototype")
public class StaffAction extends BaseAction{
private StaffService staffService;
private List<Staff> staffList;
private Staff staff;
private Role role;
private PersimissionsService persimissionsService;
private Pager pager;
private List<Integer> pageno;
public List<Integer> getPageno() {
return pageno;
}
public void setPageno(List<Integer> pageno) {
this.pageno = pageno;
}
public Pager getPager() {
return pager;
}
public void setPager(Pager pager) {
this.pager = pager;
}
public PersimissionsService getPersimissionsService() {
return persimissionsService;
}
@Resource
public void setPersimissionsService(PersimissionsService persimissionsService) {
this.persimissionsService = persimissionsService;
}
private RoleService roleService;
private List<Role> rolelist;
public RoleService getRoleService() {
return roleService;
}
@Resource
public void setRoleService(RoleService roleService) {
this.roleService = roleService;
}
public List<Role> getRolelist() {
return rolelist;
}
public void setRolelist(List<Role> rolelist) {
this.rolelist = rolelist;
}
public StaffService getStaffService() {
return staffService;
}
@Resource
public void setStaffService(StaffService staffService) {
this.staffService = staffService;
}
public List<Staff> getStaffList() {
return staffList;
}
public void setStaffList(List<Staff> staffList) {
this.staffList = staffList;
}
public Staff getStaff() {
return staff;
}
public void setStaff(Staff staff) {
this.staff = staff;
}
public String save(){
staffService.save(staff);
return "save";
}
public String delete(){
staffService.delete(staff);
return "delete";
}
public String load(){
try {
rolelist=roleService.findAll();
System.out.println("修改角色的大小"+rolelist.size());
setAttribute("rolelist", rolelist);
staff = staffService.load(staff.getStaffId());
System.out.println(staff.getStaffId());
System.out.println(staff.getNikename());
return "load";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "error";
}
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
public String update(){
try {
role=roleService.loadByName(role);
System.out.println("职位变为"+role.getId()+role.getName());
staff.setRoleName(role.getName());
staff.setRoleId(role.getId());
System.out.println(staff.getStaffId());
System.out.println(staff.getStaffName());
System.out.println(staff.getRoleName());
System.out.println(staff.getStaffCount());
staffService.update(staff);
return "update";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "error";
}
}
public String findAll(){
try {
if(pager==null){
pager = new Pager();
}
pager = staffService.findAll(pager.pageSize, pager.pageNo);
staffList = (List<Staff>) pager.getResultList();
System.out.println("Action"+pager.getRowCount());
pageno = new ArrayList<Integer>();
for(int i = 1;i <= pager.getPageCount();i++){
pageno.add(i);
}
setAttribute("pageno", pageno);
return"findAll";
} catch (Exception e) {
System.out.println("出错信息"+e.getMessage());
return "error";
}
}
public String check(){
staff=staffService.check(staff);
if(staff!=null){
ActionContext.getContext().getSession().put("staff",staff);
role=roleService.load(staff.getRoleId());
System.out.println("用户的角色为"+role.getName());
try {
List rolePer = persimissionsService.loadRolePer(role.getId());
List<Persimissions> r1=persimissionsService.findRolePer(rolePer);
System.out.println("此用户具有"+r1.size()+"列表");
ActionContext.getContext().getSession().put("role",role);
ActionContext.getContext().getSession().put("indexBar",r1);
System.out.println(ActionContext.getContext().getSession().get("role"));
System.out.println(ActionContext.getContext().getSession().get("indexBar"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "success";
}
else{
return "error";
}
}
}