Skip to content

Commit

Permalink
修复权限模块bug
Browse files Browse the repository at this point in the history
  • Loading branch information
leslie52 committed Aug 15, 2016
1 parent c9ff190 commit 578e8b1
Show file tree
Hide file tree
Showing 45 changed files with 554 additions and 802 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">

<!-- 定时任务 -->
<bean id="reconciliationTask" class="com.roncoo.app.reconciliation.ReconciliationTask" />
<bean id="reconciliationTask" class="com.roncoo.pay.app.reconciliation.ReconciliationTask" />
<task:scheduled-tasks>
<!-- 每天上午10点15分触发 -->
<task:scheduled ref="reconciliationTask" method="main" cron="0 15 10 * * ?" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static Map<String, Map<String, Object>> toMap() {
for (int num = 0; num < ary.length; num++) {
Map<String, Object> map = new HashMap<String, Object>();
String key = ary[num].name();
map.put("value", ary[num].name());
map.put("desc", ary[num].getDesc());
enumMap.put(key, map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ public interface PmsRolePermissionDao extends PermissionBaseDao<PmsRolePermissio
* @return
*/
public List<PmsRolePermission> listByRoleIds(String roleIdsStr);

public void deleteByRoleIdAndPermissionId(Long roleId, Long permissionId);

public void deleteByRoleId(Long roleId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package com.roncoo.pay.permission.dao.impl;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -54,4 +56,15 @@ public List<PmsRolePermission> listByRoleIds(String roleIdsStr) {
List<String> roldIds = Arrays.asList(roleIdsStr.split(","));
return super.getSqlSession().selectList(getStatement("listByRoleIds"), roldIds);
}

public void deleteByRoleIdAndPermissionId(Long roleId, Long permissionId){
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("roleId", roleId);
paramMap.put("permissionId", permissionId);
super.getSqlSession().delete(getStatement("deleteByRoleIdAndPermissionId"), paramMap);
}

public void deleteByRoleId(Long roleId){
super.getSqlSession().delete(getStatement("deleteByRoleId"), roleId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ public interface PmsMenuRoleService {
*/
public void deleteByRoleId(Long roleId);

public void saveRoleMenu(Long roleId, String roleMenuStr);

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,10 @@ public interface PmsPermissionService {
* @return
*/
String getPermissionIdsByRoleId(Long roleId);

/**
* 查询所有的权限
*/
List<PmsPermission> listAll();

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@ public interface PmsRolePermissionService {
* @return
*/
PageBean listPage(PageParam pageParam, PmsRolePermission pmsRolePermission);

/**
* 保存角色和权限之间的关联关系
*/
void saveRolePermission(Long roleId, String rolePermissionStr);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.druid.util.StringUtils;
import com.roncoo.pay.permission.dao.PmsMenuRoleDao;
import com.roncoo.pay.permission.entity.PmsMenuRole;
import com.roncoo.pay.permission.service.PmsMenuRoleService;
Expand Down Expand Up @@ -62,4 +64,20 @@ public void deleteByRoleId(Long roleId) {
pmsMenuRoleDao.deleteByRoleId(roleId);
}

@Transactional(rollbackFor = Exception.class)
public void saveRoleMenu(Long roleId, String roleMenuStr){
// 删除原来的角色与权限关联
pmsMenuRoleDao.deleteByRoleId(roleId);
if (!StringUtils.isEmpty(roleMenuStr)) {
// 创建新的关联
String[] menuIds = roleMenuStr.split(",");
for (int i = 0; i < menuIds.length; i++) {
Long menuId = Long.valueOf(menuIds[i]);
PmsMenuRole item = new PmsMenuRole();
item.setMenuId(menuId);
item.setRoleId(roleId);
pmsMenuRoleDao.insert(item);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.roncoo.pay.permission.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand All @@ -25,6 +26,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.roncoo.pay.common.core.enums.PublicStatusEnum;
import com.roncoo.pay.common.core.page.PageBean;
import com.roncoo.pay.common.core.page.PageParam;
import com.roncoo.pay.permission.dao.PmsOperatorDao;
Expand Down Expand Up @@ -153,16 +155,16 @@ public void saveOperator(PmsOperator pmsOperator, String roleOperatorStr) {
pmsOperatorDao.insert(pmsOperator);
// 保存角色关联信息
if (StringUtils.isNotBlank(roleOperatorStr) && roleOperatorStr.length() > 0) {
saveOrUpdateOperatorRole(pmsOperator.getId(), roleOperatorStr);
saveOrUpdateOperatorRole(pmsOperator, roleOperatorStr);
}
}

/**
* 保存用户和角色之间的关联关系
*/
private void saveOrUpdateOperatorRole(long operatorId, String roleIdsStr) {
private void saveOrUpdateOperatorRole(PmsOperator pmsOperator, String roleIdsStr) {
// 删除原来的角色与操作员关联
List<PmsOperatorRole> listPmsOperatorRoles = pmsOperatorRoleDao.listByOperatorId(operatorId);
List<PmsOperatorRole> listPmsOperatorRoles = pmsOperatorRoleDao.listByOperatorId(pmsOperator.getId());
Map<Long, PmsOperatorRole> delMap = new HashMap<Long, PmsOperatorRole>();
for (PmsOperatorRole pmsOperatorRole : listPmsOperatorRoles) {
delMap.put(pmsOperatorRole.getRoleId(), pmsOperatorRole);
Expand All @@ -174,8 +176,11 @@ private void saveOrUpdateOperatorRole(long operatorId, String roleIdsStr) {
long roleId = Long.parseLong(roleIds[i]);
if (delMap.get(roleId) == null) {
PmsOperatorRole pmsOperatorRole = new PmsOperatorRole();
pmsOperatorRole.setOperatorId(operatorId);
pmsOperatorRole.setOperatorId(pmsOperator.getId());
pmsOperatorRole.setRoleId(roleId);
pmsOperatorRole.setCreater(pmsOperator.getCreater());
pmsOperatorRole.setCreateTime(new Date());
pmsOperatorRole.setStatus(PublicStatusEnum.ACTIVE.name());
pmsOperatorRoleDao.insert(pmsOperatorRole);
} else {
delMap.remove(roleId);
Expand All @@ -186,7 +191,7 @@ private void saveOrUpdateOperatorRole(long operatorId, String roleIdsStr) {
Iterator<Long> iterator = delMap.keySet().iterator();
while (iterator.hasNext()) {
long roleId = iterator.next();
pmsOperatorRoleDao.deleteByRoleIdAndOperatorId(roleId, operatorId);
pmsOperatorRoleDao.deleteByRoleIdAndOperatorId(roleId, pmsOperator.getId());
}
}

Expand All @@ -201,7 +206,7 @@ private void saveOrUpdateOperatorRole(long operatorId, String roleIdsStr) {
public void updateOperator(PmsOperator pmsOperator, String roleOperatorStr) {
pmsOperatorDao.update(pmsOperator);
// 更新角色信息
this.saveOrUpdateOperatorRole(pmsOperator.getId(), roleOperatorStr);
this.saveOrUpdateOperatorRole(pmsOperator, roleOperatorStr);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,11 @@ public String getPermissionIdsByRoleId(Long roleId) {
return actionIds.toString();
}

/**
* 查询所有的权限
*/
public List<PmsPermission> listAll() {
Map<String, Object> paramMap = new HashMap<String, Object>();
return pmsPermissionDao.listBy(paramMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.druid.util.StringUtils;
import com.roncoo.pay.common.core.page.PageBean;
Expand Down Expand Up @@ -134,5 +136,25 @@ public PageBean listPage(PageParam pageParam, PmsRolePermission pmsRolePermissio
Map<String, Object> paramMap = new HashMap<String, Object>();
return pmsRolePermissionDao.listPage(pageParam, paramMap);
}

/**
* 保存角色和权限之间的关联关系
*/
@Transactional(rollbackFor = Exception.class)
public void saveRolePermission(Long roleId, String rolePermissionStr){
// 删除原来的角色与权限关联
pmsRolePermissionDao.deleteByRoleId(roleId);
if (!StringUtils.isEmpty(rolePermissionStr)) {
// 创建新的关联
String[] permissionIds = rolePermissionStr.split(",");
for (int i = 0; i < permissionIds.length; i++) {
Long permissionId = Long.valueOf(permissionIds[i]);
PmsRolePermission item = new PmsRolePermission();
item.setPermissionId(permissionId);
item.setRoleId(roleId);
pmsRolePermissionDao.insert(item);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
where ID = #{id} and VERSION = #{version}
</update>

<delete id="deleteById" parameterType="long">
<delete id="deleteByPrimaryKey" parameterType="long">
delete from
<include refid="pms_menu" />
where ID = #{id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
</select>

<select id="listByRoleId" parameterType="long" resultType="com.roncoo.pay.permission.entity.PmsMenuRole">
select * from
select d.id as "id",
d.role_id as "roleId",
d.menu_id as "menuId"
from
<include refid="pms_menu_role" />
d
where role_id = #{roleId}
</select>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<!-- Pms权限管理:操作员表 -->
<sql id="pms_operator"> PMS_OPERATOR </sql>
<sql id="pms_operator_role"> PMS_OPERATOR_ROLE </sql>
<sql id="pms_role_operator"> PMS_ROLE_OPERATOR </sql>

<resultMap id="beanMap" type="com.roncoo.pay.permission.entity.PmsOperator">
<id column="id" property="id" jdbcType="INTEGER" />
Expand Down Expand Up @@ -72,7 +72,7 @@
order by ID
</select>

<delete id="deleteById" parameterType="Long">
<delete id="deleteByPrimaryKey" parameterType="Long">
delete from
<include refid="pms_operator" />
where ID = #{id}
Expand All @@ -82,7 +82,7 @@
<!-- Equal query -->
<if test="loginName != null and loginName != ''"> and login_name = #{loginName}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="status != null and status != ''"> and type = #{type}</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<!-- Like query -->
<if test="realName != null and realName != ''"> and REALNAME like CONCAT(CONCAT('%', #{realName}), '%')</if>
</sql>
Expand Down Expand Up @@ -110,7 +110,7 @@
select O.* from
<include refid="pms_operator" />
O LEFT JOIN
<include refid="pms_operator_role" />
<include refid="pms_role_operator" />
RO ON
O.ID = RO.operator_id WHERE RO.role_id = #{roleId}
</select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,16 @@
<include refid="pms_permission" />
where permission = #{permission} and id != #{id}
</select>

<select id="selectByPrimaryKey" parameterType="Long" resultMap="beanMap">
select
*
from
<include refid="pms_permission" />
where id = #{id}
</select>


<delete id="deleteById" parameterType="Long">
<delete id="deleteByPrimaryKey" parameterType="Long">
delete from
<include refid="pms_permission" />
where id = #{id}
Expand All @@ -108,7 +115,7 @@
<where>
<include refid="condition_sql" />
</where>

order by create_time desc limit #{pageFirst}, #{pageSize}
</select>

<!-- 分页查询时要用到的总数统计 -->
Expand All @@ -120,5 +127,14 @@
</where>
</select>

<select id="listBy" parameterType="java.util.Map" resultMap="beanMap">
select
*
from
<include refid="pms_permission" />
<where>
<include refid="condition_sql" />
</where>
</select>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
order by id
</select>

<delete id="deleteById" parameterType="Long">
<delete id="deleteByPrimaryKey" parameterType="Long">
delete from
<include refid="pms_role" />
where id = #{id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@
<include refid="pms_role_permission" />
where role_id = #{roleId}
</delete>

<delete id="deleteByRoleIdAndPermissionId" parameterType="java.util.Map">
delete from
<include refid="pms_role_permission" />
where role_id = #{roleId} and permission_id = #{permissionId}
</delete>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void buildAdminPermissionTree(String pId, StringBuffer treeBuf, List men
String level = map.get("level").toString();// 菜单层级(1、2、3、4)
String url = map.get("url").toString(); // ACTION访问地址
String navTabId = "";
if (StringUtil.isEmpty(map.get("targetName"))) {
if (!StringUtil.isEmpty(map.get("targetName"))) {
navTabId = map.get("targetName").toString(); // 用于刷新查询页面
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,17 @@ public String addPmsMenu(HttpServletRequest req, PmsMenu pmsMenu, Model model, D
if (list.size() > 0) {
return operateError("同级菜单名称不能重复", model);
}
pmsMenu.setCreater(getPmsOperator().getRealName());
pmsMenu.setCreater(getPmsOperator().getLoginName());
pmsMenu.setStatus(PublicStatusEnum.ACTIVE.name());
pmsMenu.setIsLeaf("YES");
if (null != pmsMenu.getParent().getId()) {
pmsMenu.setLevel(pmsMenu.getParent().getLevel()+1);
}else{
pmsMenu.setLevel(1L);
PmsMenu parent = new PmsMenu();
parent.setId(0l);
pmsMenu.setParent(parent);
}
pmsMenuService.savaMenu(pmsMenu);
} catch (Exception e) {
// 记录系统操作日志
Expand Down
Loading

0 comments on commit 578e8b1

Please sign in to comment.