| @@ -13,7 +13,6 @@ import com.iformall.enums.EnumFlowPermissionType; | |||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.shiro.PasswordHelper; | import com.iformall.shiro.PasswordHelper; | ||||
| import com.iformall.shiro.UserSession; | import com.iformall.shiro.UserSession; | ||||
| import com.iformall.utils.Constant; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| @@ -21,7 +20,6 @@ import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.collections.map.HashedMap; | import org.apache.commons.collections.map.HashedMap; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.apache.shiro.SecurityUtils; | import org.apache.shiro.SecurityUtils; | ||||
| import org.apache.shiro.authz.annotation.RequiresPermissions; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -299,6 +297,7 @@ public class MallUserInfoController extends BaseController { | |||||
| // TODO 请用 /menu/nav 获取菜单及权限 | // TODO 请用 /menu/nav 获取菜单及权限 | ||||
| List<Long> menuList = mallPermissionService.queryAdminMenuList(info); | List<Long> menuList = mallPermissionService.queryAdminMenuList(info); | ||||
| //list.stream().distinct().collect(Collectors.joining(",")); | |||||
| StringBuilder sb = new StringBuilder(); | StringBuilder sb = new StringBuilder(); | ||||
| boolean bFirst = true; | boolean bFirst = true; | ||||
| for(Long id: menuList) { | for(Long id: menuList) { | ||||
| @@ -50,12 +50,6 @@ public class SysMenuController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private MallUserInfoService mallUserInfoService; | private MallUserInfoService mallUserInfoService; | ||||
| @Autowired | |||||
| private MallRoleService mallRoleService; | |||||
| @Autowired | |||||
| private MallRolePermissionService mallRolePermissionService; | |||||
| @ApiOperation("导航菜单") | @ApiOperation("导航菜单") | ||||
| @GetMapping("/nav") | @GetMapping("/nav") | ||||
| public ResultData nav(){ | public ResultData nav(){ | ||||
| @@ -136,45 +130,6 @@ public class SysMenuController extends BaseController { | |||||
| return new ResultData(Result.SUCCESS, "成功", mallPermissionService.getById(id)); | return new ResultData(Result.SUCCESS, "成功", mallPermissionService.getById(id)); | ||||
| } | } | ||||
| @ApiOperation("用户菜单权限升级") | |||||
| @GetMapping("/upgradeMenus") | |||||
| //@RequiresPermissions("sys:menu:info") | |||||
| @SystemControllerLog(description = "用户管理-权限升级") | |||||
| public ResultData upgradeMenus() { | |||||
| logger.debug("[" + getIpAddr() + "] MallPermissionController::upgradeMenus"); | |||||
| MallUserInfo userInfo = getUser(); | |||||
| if(userInfo.isFmSuperAdmin()) { | |||||
| // 已有Role | |||||
| MallRole q = new MallRole(); | |||||
| List<MallRole> mallRoleList = mallRoleService.getList(q); | |||||
| for(MallRole mallRole: mallRoleList) { | |||||
| MallRolePermission qRP = new MallRolePermission(); | |||||
| qRP.setRoleId(mallRole.getId()); | |||||
| List<MallRolePermission> mallRolePermissionList = mallRolePermissionService.getList(qRP); | |||||
| if(mallRolePermissionList.stream().allMatch((rolePermission->(rolePermission.getPermissionId().longValue() <= (long)EnumMenuType.HARDWARE.getCode())))){ | |||||
| // 添加子权限给此role | |||||
| for(MallRolePermission mRP: mallRolePermissionList) { | |||||
| List<Long> pList = new ArrayList<>(); | |||||
| // 二级菜单 | |||||
| List<MallPermission> subList1 = mallPermissionService.getByParentId(mRP.getPermissionId()); | |||||
| for(MallPermission mp: subList1) { | |||||
| pList.add(mp.getId()); | |||||
| // 三级菜单 | |||||
| List<MallPermission> subList2 = mallPermissionService.getByParentId(mRP.getPermissionId()); | |||||
| if(subList2.size() > 0) { | |||||
| subList2.stream().forEach(smp->{ | |||||
| pList.add(smp.getId()); | |||||
| }); | |||||
| } | |||||
| } | |||||
| mallRolePermissionService.savePermissions(mRP.getTenantId(), mRP.getRoleId(), (Long[])pList.toArray()); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||||
| } | |||||
| @Autowired | @Autowired | ||||
| private RequestMappingHandlerMapping requestMappingHandlerMapping; | private RequestMappingHandlerMapping requestMappingHandlerMapping; | ||||
| @@ -46,10 +46,10 @@ public class MyShiroRealm extends AuthorizingRealm { | |||||
| throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | ||||
| } | } | ||||
| // 租户1为预留系统管理端 | // 租户1为预留系统管理端 | ||||
| //if(user.getTenantId().equals("1")) { | |||||
| // // 只支持租户为1的用户 | |||||
| // throw new UnknownAccountException("租户不支持"); | |||||
| //} | |||||
| if(user.getTenantId().equals("1")) { | |||||
| // 只支持租户为1的用户 | |||||
| throw new UnknownAccountException("租户不支持"); | |||||
| } | |||||
| if(user.getStatus()==null || | if(user.getStatus()==null || | ||||
| !EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) {//用户被禁用 | !EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) {//用户被禁用 | ||||
| throw new DisabledAccountException(ErrorCode.USER_IS_LOCKED.getMessage()); | throw new DisabledAccountException(ErrorCode.USER_IS_LOCKED.getMessage()); | ||||
| @@ -17,10 +17,10 @@ import java.util.List; | |||||
| public class MallRolePermissionServiceImpl implements MallRolePermissionService { | public class MallRolePermissionServiceImpl implements MallRolePermissionService { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| @Autowired | |||||
| MallRolePermissionMapper mallUserRolePermissionMapper; | MallRolePermissionMapper mallUserRolePermissionMapper; | ||||
| @Override | @Override | ||||
| public PageInfo<MallRolePermission> listAsPage(MallRolePermission record, Integer pageIndex, Integer pageSize) { | public PageInfo<MallRolePermission> listAsPage(MallRolePermission record, Integer pageIndex, Integer pageSize) { | ||||
| @@ -42,7 +42,7 @@ public class MallRolePermissionServiceImpl implements MallRolePermissionService | |||||
| if (record.getId() == null) { | if (record.getId() == null) { | ||||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| record.setId(idWorker.nextId()); | |||||
| record.setId(idWorker.nextId()); | |||||
| mallUserRolePermissionMapper.insertSelective(record); | mallUserRolePermissionMapper.insertSelective(record); | ||||
| } else { | } else { | ||||
| mallUserRolePermissionMapper.updateByPrimaryKeySelective(record); | mallUserRolePermissionMapper.updateByPrimaryKeySelective(record); | ||||
| @@ -53,32 +53,26 @@ public class MallRolePermissionServiceImpl implements MallRolePermissionService | |||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| mallUserRolePermissionMapper.deleteByPrimaryKey(id); | mallUserRolePermissionMapper.deleteByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public void savePermissions(String tenantId,Long roleId, Long[] perId) { | |||||
| // Map<String,Object> map = new HashMap<>(); | |||||
| // map.put("roleId", roleId); | |||||
| mallUserRolePermissionMapper.deleteByRoleId(roleId); | |||||
| for(Long pId:perId){ | |||||
| MallRolePermission permission =new MallRolePermission(); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| permission.setId(idWorker.nextId()); | |||||
| permission.setPermissionId(pId); | |||||
| permission.setTenantId(tenantId); | |||||
| permission.setRoleId(roleId); | |||||
| mallUserRolePermissionMapper.insert(permission); | |||||
| } | |||||
| } | |||||
| public void deleteByRoleId(Long roleId) { | |||||
| mallUserRolePermissionMapper.deleteByRoleId(roleId); | |||||
| } | |||||
| @Override | |||||
| public void savePermissions(String tenantId, Long roleId, Long[] perId) { | |||||
| mallUserRolePermissionMapper.deleteByRoleId(roleId); | |||||
| for (Long pId : perId) { | |||||
| MallRolePermission permission = new MallRolePermission(); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| permission.setId(idWorker.nextId()); | |||||
| permission.setPermissionId(pId); | |||||
| permission.setTenantId(tenantId); | |||||
| permission.setRoleId(roleId); | |||||
| mallUserRolePermissionMapper.insert(permission); | |||||
| } | |||||
| } | |||||
| public void deleteByRoleId(Long roleId) { | |||||
| mallUserRolePermissionMapper.deleteByRoleId(roleId); | |||||
| } | |||||
| } | } | ||||
| @@ -1,57 +1,55 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="com.iformall.mapper.MallRolePermissionMapper"> | <mapper namespace="com.iformall.mapper.MallRolePermissionMapper"> | ||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.MallRolePermission"> | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||||
| <result column="permission_id" jdbcType="VARCHAR" property="permissionId" /> | |||||
| <result column="role_id" jdbcType="VARCHAR" property="roleId" /> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.MallRolePermission"> | |||||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||||
| <result column="permission_id" jdbcType="VARCHAR" property="permissionId"/> | |||||
| <result column="role_id" jdbcType="VARCHAR" property="roleId"/> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`permission_id`,`role_id` | `id`,`tenant_id`,`permission_id`,`role_id` | ||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != permissionId "> | |||||
| and `permission_id` like concat('%', #{permissionId},'%') | |||||
| </if> | |||||
| <if test=" null != roleId "> | |||||
| and `role_id` like concat('%', #{roleId},'%') | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.MallRolePermission" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from mall_role_permission | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| <delete id="deleteByRoleId"> | |||||
| delete from mall_role_permission where role_id=#{roleId} | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != permissionId "> | |||||
| and `permission_id` = #{permissionId} | |||||
| </if> | |||||
| <if test=" null != roleId "> | |||||
| and `role_id` = #{roleId} | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.MallRolePermission" resultMap="BaseResultMap"> | |||||
| select | |||||
| <include refid="allColumns"/> | |||||
| from mall_role_permission | |||||
| <include refid="dynamicWhereConditions"/> | |||||
| </select> | |||||
| <delete id="deleteByRoleId"> | |||||
| delete from mall_role_permission where role_id=#{roleId} | |||||
| </delete> | </delete> | ||||
| </mapper> | </mapper> | ||||