package cn.edu.hpu.tax.core.content;
import java.util.HashMap;
import java.util.Map;
public class Constant {
/*-----------------系统权限集合-------------------*/
public static String PRIVILEGE_XZGL="xzgl";
public static String PRIVILEGE_HQFW="hqfw";
public static String PRIVILEGE_ZXXX="zxxx";
public static String PRIVILEGE_NSFW="nsfw";
public static String PRIVILEGE_SPACE="spaces";
public static Map PRIVILEGE_MAP;
static{
PRIVILEGE_MAP=new HashMap();
PRIVILEGE_MAP.put(PRIVILEGE_XZGL, "行政管理");
PRIVILEGE_MAP.put(PRIVILEGE_HQFW, "后勤服务");
PRIVILEGE_MAP.put(PRIVILEGE_ZXXX, "在线学习");
PRIVILEGE_MAP.put(PRIVILEGE_NSFW, "纳税服务");
PRIVILEGE_MAP.put(PRIVILEGE_SPACE, "我的空间");
}
}
package cn.edu.hpu.tax.role.entity;
import java.io.Serializable;
import java.util.Set;
public class Role implements Serializable {
private String roleId;
private String name;
private String state;
private Set rolePrivileges;
//角色状态
public final static String ROLE_STATE_VALID = "1";//有效
public final static String ROLE_STATE_INVALID = "0";//无效
public Role() {
super();
// TODO Auto-generated constructor stub
}
public Role(String roleId, String name, String state,
Set rolePrivileges) {
super();
this.roleId = roleId;
this.name = name;
this.state = state;
this.rolePrivileges = rolePrivileges;
}
public String getRoleId() {
return roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Set getRolePrivileges() {
return rolePrivileges;
}
public void setRolePrivileges(Set rolePrivileges) {
this.rolePrivileges = rolePrivileges;
}
}
package cn.edu.hpu.tax.role.entity;
import java.io.Serializable;
public class RolePrivilege implements Serializable {
//联合主键
private RolePrivilegeId id;
public RolePrivilege(){
}
public RolePrivilege(RolePrivilegeId id) {
super();
this.id = id;
}
public RolePrivilegeId getId() {
return id;
}
public void setId(RolePrivilegeId id) {
this.id = id;
}
}
package cn.edu.hpu.tax.role.entity;
import java.io.Serializable;
public class RolePrivilegeId implements Serializable{
private Role role;
private String code;
public RolePrivilegeId(){
}
public RolePrivilegeId(Role role, String code) {
super();
this.role = role;
this.code = code;
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
//重写hashCode与equals方法(不用自己写,MyEclipse可生成)
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((code == null) ? 0 : code.hashCode());
result = prime * result + ((role == null) ? 0 : role.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RolePrivilegeId other = (RolePrivilegeId) obj;
if (code == null) {
if (other.code != null)
return false;
} else if (!code.equals(other.code))
return false;
if (role == null) {
if (other.role != null)
return false;
} else if (!role.equals(other.role))
return false;
return true;
}
}
package cn.edu.hpu.tax.role.dao;
import cn.edu.hpu.tax.core.dao.BaseDao;
import cn.edu.hpu.tax.role.entity.Role;
public interface RoleDao extends BaseDao {
public void deletePrivilegeByRoleId(String roleId);
}
package cn.edu.hpu.tax.role.dao.impl;
import org.hibernate.Query;
import cn.edu.hpu.tax.core.dao.impl.BaseDaoImpl;
import cn.edu.hpu.tax.role.dao.RoleDao;
import cn.edu.hpu.tax.role.entity.Role;
public class RoleDaoImpl extends BaseDaoImpl implements RoleDao{
@Override
public void deletePrivilegeByRoleId(String roleId) {
//hql语句是按照类来的,不是按照数据库表来写语句的
Query query=getSession().createQuery("DELETE FROM RolePrivilege WHERE id.role.roleId=?");
query.setParameter(0, roleId);
query.executeUpdate();
}
}
package cn.edu.hpu.tax.role.service;
import java.io.Serializable;
import java.util.List;
import cn.edu.hpu.tax.role.entity.Role;
public interface RoleService {
//新增
public void save(Role role);
//更新
public void update(Role role);
//根据id删除
public void delete(Serializable id);
//根据id查找
public Role findObjectById(Serializable id);
//查找列表
public List findObjects();
}
package cn.edu.hpu.tax.role.service.impl;
import java.io.Serializable;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import cn.edu.hpu.tax.role.dao.RoleDao;
import cn.edu.hpu.tax.role.entity.Role;
import cn.edu.hpu.tax.role.service.RoleService;
@Service("roleService")
public class RoleServiceImpl implements RoleService{
@Resource
private RoleDao roleDao;
@Override
public void save(Role role) {
roleDao.save(role);
}
@Override
public void update(Role role) {
//1.删除该角色对应的所有权限
roleDao.deletePrivilegeByRoleId(role.getRoleId());
//2.更新角色及其权限
roleDao.update(role);
}
@Override
public void delete(Serializable id) {
roleDao.delete(id);
}
@Override
public Role findObjectById(Serializable id) {
return roleDao.findObjectById(id);
}
@Override
public List findObjects() {
return roleDao.findObjects();
}
}
后面内容在下一篇:http://blog.csdn.net/acmman/article/details/49513077
转载请注明出处:http://blog.csdn.net/acmman/article/details/49512903