package action; import java.util.ArrayList; import java.util.List; import java.util.Set; import util.MyJson; import util.MyRight; import biz.CommonBiz; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionContext; import entity.OaRight; import entity.OaRole; import entity.OaUser; public class RightAction { private static final String TOMENU = "tomenu"; private static final String TOROLE = "torole"; private CommonBiz commonBiz; private List<MyRight> myRights; private OaRole role; private String rightIds; public String getRightIds() { return rightIds; } public void setRightIds(String rightIds) { this.rightIds = rightIds; } public OaRole getRole() { return role; } public void setRole(OaRole role) { this.role = role; } public List<MyRight> getMyRights() { return myRights; } public void setMyRights(List<MyRight> myRights) { this.myRights = myRights; } public CommonBiz getCommonBiz() { return commonBiz; } public void setCommonBiz(CommonBiz commonBiz) { this.commonBiz = commonBiz; } /** * 获取当前用户的权限 * @return */ public String getRightList(){ OaUser user=(OaUser) ActionContext.getContext().getSession().get("user"); Set<OaRight> rights=user.getOaRole().getOaRights(); myRights=new ArrayList<MyRight>(); for (OaRight right : rights) { if (right.getPid()==0) { MyRight myRight=new MyRight(); myRight.setOaRight(right); for (OaRight right2 : rights) { if (right2.getPid().toString().equals(right.getRightId())) { myRight.getRightSubs().add(right2); } } myRights.add(myRight); } } return TOMENU; } /** * 跳转到角色管理页面 * @return */ public String toRole(){ return TOROLE; } /** * 查询所有角色 * @return */ public String findRoleList(){ List<OaRole> roleList=commonBiz.getOaRoleDAO().findAll(); String msg = "{totalCount:" + roleList.size() + ",result:"; msg += MyJson.toJsonStr(roleList, "oaRights"); msg += "}"; ActionContext.getContext().put("msg", msg); return Action.SUCCESS; } /** * 添加角色 * @return */ public String addRole(){ commonBiz.getOaRoleDAO().save(role); ActionContext.getContext().put("msg", "{success:true,msg:'添加成功'}"); return Action.SUCCESS; } /** * 修改角色 * @return */ public String updateRole(){ OaRole oaRole=commonBiz.getOaRoleDAO().findById(role.getRoleId()); oaRole.setRoleName(role.getRoleName()); commonBiz.getOaRoleDAO().merge(oaRole); ActionContext.getContext().put("msg", "{success:true,msg:'修改成功'}"); return Action.SUCCESS; } /** * 删除角色 * @return */ public String deleteRole(){ commonBiz.getOaRoleDAO().delete(role); ActionContext.getContext().put("msg", "{success:true,msg:'删除成功'}"); return Action.SUCCESS; } /** * 查询角色已有权限和可分配权限 * @return */ public String findRightsByRoleId(){ //全部权限 List<OaRight> rightList=commonBiz.getOaRightDAO().findAll(); //获取当前角色 role=commonBiz.getOaRoleDAO().findById(role.getRoleId()); //已有的权限 Set<OaRight> hasRights=role.getOaRights(); //可分配的权限 List<OaRight> notRights=new ArrayList<OaRight>(); for (OaRight right : rightList) { boolean flag=true; for (OaRight r : hasRights) { if (right.getRightId().equals(r.getRightId())) { flag=false; } } if (flag) { notRights.add(right); } } String msg = "{hasRights:"; msg += MyJson.toJsonStr(hasRights, new String[]{"oaRoles","url"}); msg += ",notRights:"+MyJson.toJsonStr(notRights, new String[]{"oaRoles","url"}); msg += "}"; ActionContext.getContext().put("msg", msg); return Action.SUCCESS; } /** * 执行权限更改 * @return */ public String doUpdateRight(){ //获取当前角色 role=commonBiz.getOaRoleDAO().findById(role.getRoleId()); String[] ids=rightIds.split(","); //清空原有权限 role.getOaRights().removeAll(role.getOaRights()); if (rightIds!=null&&!rightIds.equals("")) { for (String id : ids) { OaRight right=commonBiz.getOaRightDAO().findById(id); role.getOaRights().add(right); right.getOaRoles().add(role); } } commonBiz.getOaRoleDAO().merge(role); ActionContext.getContext().put("msg", "{success:true,msg:'分配成功'}"); return Action.SUCCESS; } }

lvdong2023 LV10
2023年5月18日
微信网友_5963854197018624 LV7
2023年4月6日
泓鼎168 LV20
2023年3月30日
cx123123 LV7
2022年5月17日
habiya LV3
2022年3月15日
ewan007 LV30
2022年3月10日
微信网友_5845420553359360 LV4
2022年2月27日
wanglinddad LV55
2021年11月6日
freeblow LV2
2021年5月20日
and123456 LV11
2021年5月11日