/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.accp.web.action;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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.accp.model.Attendancetime;
import com.accp.model.Iattendance;
import com.accp.model.Irole;
import com.accp.model.Iuser;
import com.accp.model.UserRole;
import com.accp.service.impl.AttendanceServiceImpl;
import com.accp.service.impl.AttendancetimeServiceImpl;
import com.accp.service.impl.MenuServiceImpl;
import com.accp.service.impl.RoleServiceImpl;
import com.accp.service.impl.UserRoleServiceImpl;
import com.accp.service.impl.UserServiceImpl;
import com.accp.vo.ParentNodeVo;
/**
* MyEclipse Struts Creation date: 04-27-2008
*
* XDoclet definition:
*
* @struts.action path="/role" name="roleForm" input="/form/role.jsp"
* parameter="action" scope="request" validate="true"
*/
public class RoleAction extends DispatchAction {
private AttendancetimeServiceImpl serviceAttendancetime;
private AttendanceServiceImpl serviceAttendance;
private RoleServiceImpl serviceRole;
private UserRoleServiceImpl serviceUserRole;
private UserServiceImpl serviceUser;
private MenuServiceImpl serviceMenu;
public void setServiceMenu(MenuServiceImpl serviceMenu) {
this.serviceMenu = serviceMenu;
}
public void setServiceUserRole(UserRoleServiceImpl serviceUserRole) {
this.serviceUserRole = serviceUserRole;
}
public void setServiceRole(RoleServiceImpl serviceRole) {
this.serviceRole = serviceRole;
}
public ActionForward getRoleNodes(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
request.setAttribute("menu", serviceMenu.getNodesByParent(new ParentNodeVo(Integer.parseInt(request.getSession().getAttribute("role").toString()),"角色管理",161)));
return mapping.findForward("getNodes");
}
public ActionForward getRoleInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
request.setAttribute("info", serviceUserRole.getAllUserRole());
return mapping.findForward("showInfo");
}
public ActionForward getUsersToCM(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
request.setAttribute("info", serviceUserRole.getUsers());
return mapping.findForward("showInfo");
}
public ActionForward toHome(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List<Irole> list = serviceRole.getAllRole();
Iuser user = (Iuser)request.getSession().getAttribute("user");
if(user!=null){
System.out.println("用户:"+user.getUname());
Attendancetime attendancetime = serviceAttendancetime.getAttendancetimeByUser(user);
Iattendance attendance = serviceAttendance.getIattendanceByUser(user);
List<Iattendance> attendances = serviceAttendance.getIattendancesByUser(user);
if(attendance==null){
attendance = new Iattendance();
attendance.setMorning(new Long(0));
attendance.setAfternoon(new Long(0));
attendance.setIuser(user);
attendance.setDatetime(new Date());
serviceAttendance.save(attendance);
}
if(attendancetime==null){
attendancetime=new Attendancetime();
attendancetime.setMorningstart(new Date());
attendancetime.setMorningstop(new Date());
attendancetime.setAfternoonstart(new Date());
attendancetime.setAfternoonstop(new Date());
attendancetime.setIdepart(user.getIdepart());
serviceAttendancetime.save(attendancetime);
}
request.getSession().setAttribute("attendancetime", attendancetime);
request.getSession().setAttribute("attendance", attendance);
request.getSession().setAttribute("attendances",attendances);
}
request.getSession().setAttribute("roles", list);
return mapping.findForward("home");
}
public ActionForward getNodes(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
StringBuffer text = new StringBuffer();
List<Irole> roles = serviceRole.getAllRole();
int id = 0;
int i = 0;
for (Irole irole : roles) {
text.append("{id:"+(++id)+",text:'"+irole.getRname()+"',iconCls:'user-suit',");
List<UserRole> userroles = serviceUserRole.getUserRoleByRoleId(new Integer(irole.getId().toString()));
if (userroles.size() > 0) {
text.append("children:[");
int j=0;
for (UserRole userRole : userroles) {
Iuser user = serviceUser.getUserById(userRole.getUserid());
text.append("{id:"+(++id)+",text:'"+user.getUname()+"',iconCls:'user-kid',leaf:true}");
if(j<userroles.size()-1){
text.append(",");
}
}
text.append("]");
}else{
text.append("leaf:true");
}
text.append("}");
if(i<roles.size()-1){
text.append(",");
}
i++;
}
request.setAttribute("menu", text);
System.out.println(text);
return mapping.findForward("getNodes");
}
public RoleServiceImpl getServiceRole() {
return serviceRole;
}
public void setServiceUser(UserServiceImpl serviceUser) {
this.serviceUser = serviceUser;
}
public void setServiceAttendance(AttendanceServiceImpl serviceAttendance) {
this.serviceAttendance = serviceAttendance;
}
public void setServiceAttendancetime(
AttendancetimeServiceImpl serviceAttendancetime) {
this.serviceAttendancetime = serviceAttendancetime;
}
}