| @@ -55,13 +55,13 @@ public class HomeController { | |||
| Subject subject = SecurityUtils.getSubject(); | |||
| UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword()); | |||
| subject.login(token); | |||
| List<MallRole> roleList = sysRoleService.findRoleByUserId(user.getId()); | |||
| if (null != roleList && roleList.size() > 0) { | |||
| List<MallPermission> permissionList = sysPermissionService | |||
| .findPermissionByRoleIds(roleList.stream().map(MallRole::getId).collect(Collectors.toList())); | |||
| user.setRole(roleList); | |||
| user.setPermission(permissionList); | |||
| } | |||
| // List<MallRole> roleList = sysRoleService.findRoleByUserId(user.getId()); | |||
| // if (null != roleList && roleList.size() > 0) { | |||
| // List<MallPermission> permissionList = sysPermissionService | |||
| // .findPermissionByRoleIds(roleList.stream().map(MallRole::getId).collect(Collectors.toList())); | |||
| // user.setRole(roleList); | |||
| // user.setPermission(permissionList); | |||
| // } | |||
| MallUserInfo info =(MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||
| info.setPassword("保密"); | |||
| System.out.println("id:"+ SecurityUtils.getSubject().getSession().getId()); | |||
| @@ -12,6 +12,7 @@ import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.MallPermission; | |||
| import com.simple.service.MallPermissionService; | |||
| import com.simple.service.MallRolePermissionService; | |||
| /** | |||
| * @author chenkx | |||
| @@ -23,6 +24,7 @@ public class MallPermissionController { | |||
| @Autowired | |||
| MallPermissionService mallPermissionService; | |||
| @GetMapping("alllist") | |||
| public ResultData alllist(String ava) { | |||
| @@ -50,6 +52,12 @@ public class MallPermissionController { | |||
| mallPermissionService.deleteById(id); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||
| } | |||
| @GetMapping("/findById") | |||
| public ResultData findById(Long id) { | |||
| mallPermissionService.getById(id); | |||
| return new ResultData(Result.SUCCESS, "成功", null); | |||
| } | |||
| } | |||
| @@ -1,32 +1,40 @@ | |||
| package com.simple.controller; | |||
| import com.simple.domain.po.MallRole; | |||
| import com.simple.service.MallRoleService; | |||
| import com.simple.service.MallRolePermissionService; | |||
| import io.swagger.annotations.Api; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.apache.log4j.Logger; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.util.Assert; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.MallRole; | |||
| import com.simple.service.MallRolePermissionService; | |||
| import com.simple.service.MallRoleService; | |||
| import io.swagger.annotations.Api; | |||
| @RestController | |||
| @RequestMapping("role") | |||
| @Api(description="角色相关接口") | |||
| public class MallRoleController { | |||
| public class MallRoleController extends BaseController{ | |||
| @Autowired | |||
| private MallRoleService sysRoleService; | |||
| @Autowired | |||
| private MallRolePermissionService SysRolePermissionService; | |||
| private MallRolePermissionService sysRolePermissionService; | |||
| private Logger logger = Logger.getLogger(MallRoleController.class); | |||
| @@ -35,6 +43,28 @@ public class MallRoleController { | |||
| final PageInfo<MallRole> page = sysRoleService.listAsPage(sysRole, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @PostMapping("saveOrUpdate") | |||
| public ResultData saveOrUpdate(@RequestBody MallRole sysRole ) { | |||
| String tenantId = getTenantId(); | |||
| int count = sysRoleService.countByName(sysRole.getName(), sysRole.getId()); | |||
| if(count>0) { | |||
| return new ResultData(ResultData.ERROR,"角色名已存在"); | |||
| } | |||
| sysRole.setTenantId(tenantId); | |||
| sysRoleService.saveOrUpdate(sysRole); | |||
| // SysRolePermissionService.deleteById(id); | |||
| if(StringUtils.isNoneBlank(sysRole.getMenus())) { | |||
| List<Long> mIds =new ArrayList<>(); | |||
| for(String mId:sysRole.getMenus().split(",")) { | |||
| mIds.add(Long.valueOf(mId)); | |||
| } | |||
| sysRolePermissionService.savePermissions(tenantId,sysRole.getId(), mIds.toArray(new Long[] {}));; | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| @PostMapping("add") | |||
| public ResultData add(MallRole sysRole) { | |||
| @@ -54,10 +84,13 @@ public class MallRoleController { | |||
| // Assert.notNull(sysRole.getName(), "角色名不能为空"); | |||
| return new ResultData(); | |||
| } | |||
| @GetMapping("/del") | |||
| public ResultData delete(Long id) { | |||
| @PostMapping("/del") | |||
| public ResultData delete(@RequestBody Long id) { | |||
| sysRoleService.deleteById(id); | |||
| sysRolePermissionService.deleteByRoleId(id); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||
| } | |||
| @@ -47,9 +47,9 @@ public class WxLevelConfigController extends BaseController | |||
| public ResultData add(@RequestBody WxLevelConfigDto dto) { | |||
| //Assert.notNull(wxLevelConfig.getName(), "角色名不能为空"); | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| String[] points = dto.getPoints().split("|"); | |||
| String[] level = dto.getLevel().split("|"); | |||
| String[] descs =dto.getDescription().split("|"); | |||
| String[] points = dto.getPoints().split("&"); | |||
| String[] level = dto.getLevel().split("&"); | |||
| String[] descs =dto.getDescription().split("&"); | |||
| String tenantId = getTenantId(); | |||
| wxLevelConfigService.deleteAll(); | |||
| for(int i=0;i<points.length;i++) { | |||
| @@ -1,11 +1,12 @@ | |||
| package com.simple.domain.po; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.*; | |||
| import java.util.*; | |||
| import java.math.*; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import javax.persistence.Id; | |||
| import java.io.Serializable; | |||
| @Table(name = "mall_permission") | |||
| public class MallPermission implements Serializable { | |||
| @@ -15,7 +16,7 @@ public class MallPermission implements Serializable { | |||
| protected Long id; | |||
| @Transient | |||
| protected List<String> ids; | |||
| protected List<Long> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| @@ -31,10 +32,11 @@ public class MallPermission implements Serializable { | |||
| return sortColumns; | |||
| } | |||
| public List<String> getIds() { | |||
| public List<Long> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<String> ids) { | |||
| public void setIds(List<Long> ids) { | |||
| this.ids = ids; | |||
| } | |||
| @@ -53,7 +55,7 @@ public class MallPermission implements Serializable { | |||
| private String available; | |||
| /*父编号**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="父编号",name="parentId") | |||
| private String parentId; | |||
| private Long parentId; | |||
| /*父编号列表**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="父编号列表",name="parentIds") | |||
| private String parentIds; | |||
| @@ -107,10 +109,10 @@ public class MallPermission implements Serializable { | |||
| public void setAvailable(String _available) { | |||
| available = _available; | |||
| } | |||
| public String getParentId() { | |||
| public Long getParentId() { | |||
| return parentId; | |||
| } | |||
| public void setParentId(String _parentId) { | |||
| public void setParentId(Long _parentId) { | |||
| parentId = _parentId; | |||
| } | |||
| public String getParentIds() { | |||
| @@ -232,9 +234,9 @@ public class MallPermission implements Serializable { | |||
| sb.append(","); | |||
| sb.append(fields[k].toString()); | |||
| } | |||
| } | |||
| public void setSortColumns(String sortColumns) | |||
| { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| @@ -242,7 +244,7 @@ public class MallPermission implements Serializable { | |||
| } | |||
| if (sortColumns.contains(",")) { | |||
| String[] cols = sortColumns.split(","); | |||
| List<Field> fList = new ArrayList(); | |||
| java.util.List<Field> fList = new java.util.ArrayList(); | |||
| for (int k = 0; k < cols.length; k++) { | |||
| fList.add(Field.valueOf(cols[k])); | |||
| } | |||
| @@ -1,11 +1,12 @@ | |||
| package com.simple.domain.po; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.*; | |||
| import java.util.*; | |||
| import java.math.*; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import javax.persistence.Id; | |||
| import java.io.Serializable; | |||
| @Table(name = "mall_role") | |||
| public class MallRole implements Serializable { | |||
| @@ -15,7 +16,7 @@ public class MallRole implements Serializable { | |||
| protected Long id; | |||
| @Transient | |||
| protected List<String> ids; | |||
| protected List<Long> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| @@ -31,10 +32,11 @@ public class MallRole implements Serializable { | |||
| return sortColumns; | |||
| } | |||
| public List<String> getIds() { | |||
| public List<Long> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<String> ids) { | |||
| public void setIds(List<Long> ids) { | |||
| this.ids = ids; | |||
| } | |||
| @@ -52,6 +54,18 @@ public class MallRole implements Serializable { | |||
| /*角色描述**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="角色描述",name="description") | |||
| private String description; | |||
| @Transient | |||
| private String menus; | |||
| public String getMenus() { | |||
| return menus; | |||
| } | |||
| public void setMenus(String menus) { | |||
| this.menus = menus; | |||
| } | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| } | |||
| @@ -118,9 +132,9 @@ public class MallRole implements Serializable { | |||
| sb.append(","); | |||
| sb.append(fields[k].toString()); | |||
| } | |||
| } | |||
| public void setSortColumns(String sortColumns) | |||
| { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| @@ -128,7 +142,7 @@ public class MallRole implements Serializable { | |||
| } | |||
| if (sortColumns.contains(",")) { | |||
| String[] cols = sortColumns.split(","); | |||
| List<Field> fList = new ArrayList(); | |||
| java.util.List<Field> fList = new java.util.ArrayList(); | |||
| for (int k = 0; k < cols.length; k++) { | |||
| fList.add(Field.valueOf(cols[k])); | |||
| } | |||
| @@ -12,7 +12,7 @@ public interface MallRolePermissionMapper extends CommonMapper<MallRolePermissio | |||
| void deleteByRoleId(Map<String, Object> map); | |||
| void deleteByRoleId(Long roleId); | |||
| @@ -44,10 +44,10 @@ public interface MallRolePermissionService { | |||
| * @param roleId | |||
| * @param perId | |||
| */ | |||
| void savePermissions(Long roleId, Long[] perId); | |||
| void savePermissions(String tenantId,Long roleId, Long[] perId); | |||
| void deleteByRoleId(Long roleId); | |||
| } | |||
| @@ -17,7 +17,9 @@ public class MallRolePermissionServiceImpl implements MallRolePermissionService | |||
| @Autowired | |||
| MallRolePermissionMapper mallUserRolePermissionMapper; | |||
| @Override | |||
| public PageInfo<MallRolePermission> listAsPage(MallRolePermission record, Integer pageIndex, Integer pageSize) { | |||
| @@ -49,18 +51,25 @@ public class MallRolePermissionServiceImpl implements MallRolePermissionService | |||
| @Override | |||
| public void savePermissions(Long roleId, Long[] perId) { | |||
| Map<String,Object> map = new HashMap<>(); | |||
| map.put("roleId", roleId); | |||
| mallUserRolePermissionMapper.deleteByRoleId(map); | |||
| 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(); | |||
| permission.setId(roleId); | |||
| 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); | |||
| } | |||
| @@ -57,7 +57,9 @@ public class MallRoleServiceImpl implements MallRoleService { | |||
| public int countByName(String name,Long id) { | |||
| Map<String,Object> map = new HashMap<>(2); | |||
| map.put("name", name); | |||
| map.put("id", id); | |||
| if(id!=null) { | |||
| map.put("id", id); | |||
| } | |||
| return mallRoleMapper.countByName(map); | |||
| } | |||
| @@ -2,12 +2,12 @@ | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.simple.mapper.MallPermissionMapper"> | |||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.MallPermission"> | |||
| <id column="id" jdbcType="VARCHAR" property="id" /> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="name" jdbcType="VARCHAR" property="name" /> | |||
| <result column="available" jdbcType="VARCHAR" property="available" /> | |||
| <result column="parent_id" jdbcType="INTEGER" property="parentId" /> | |||
| <result column="parent_ids" jdbcType="INTEGER" property="parentIds" /> | |||
| <result column="parent_id" jdbcType="BIGINT" property="parentId" /> | |||
| <result column="parent_ids" jdbcType="VARCHAR" property="parentIds" /> | |||
| <result column="permission" jdbcType="VARCHAR" property="permission" /> | |||
| <result column="resource_type" jdbcType="VARCHAR" property="resourceType" /> | |||
| <result column="url" jdbcType="VARCHAR" property="url" /> | |||
| @@ -22,7 +22,7 @@ | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` like concat('%', #{id},'%') | |||
| and `id` = #{id} | |||
| </if> | |||
| @@ -43,7 +43,7 @@ | |||
| </if> | |||
| <if test=" null != parentId "> | |||
| and `parent_id` like concat('%', #{parentId},'%') | |||
| and `parent_id` = #{parentId} | |||
| </if> | |||
| @@ -97,24 +97,6 @@ | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| <select id="findPermissionByRoleId" parameterType="java.lang.Long" resultMap="BaseResultMap"> | |||
| SELECT p.* | |||
| FROM mall_user_role_permission r2p, mall_permission p | |||
| WHERE r2p.permission_id = p.id | |||
| AND r2p.id = #{roleId} | |||
| </select> | |||
| <select id="findPermissionByRoleIds" resultMap="BaseResultMap"> | |||
| SELECT p.* | |||
| FROM mall_user_role_permission r2p, mall_permission p | |||
| WHERE resource_type='0' and r2p.permission_id = p.id | |||
| <if test="roleIds != null and roleIds.size() > 0 "> | |||
| AND r2p.id in | |||
| <foreach item="id" index="index" collection="roleIds" open="(" separator="," close=")"> | |||
| #{id} | |||
| </foreach> | |||
| </if> | |||
| </select> | |||
| @@ -2,7 +2,7 @@ | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.simple.mapper.MallRoleMapper"> | |||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.MallRole"> | |||
| <id column="id" jdbcType="VARCHAR" property="id" /> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="name" jdbcType="VARCHAR" property="name" /> | |||
| <result column="available" jdbcType="VARCHAR" property="available" /> | |||
| @@ -17,7 +17,7 @@ | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` like concat('%', #{id},'%') | |||
| and `id` = #{id} | |||
| </if> | |||
| @@ -26,7 +26,7 @@ | |||
| </if> | |||
| <if test=" null != name "> | |||
| <if test=" null != name and '' != name "> | |||
| and `name` like concat('%', #{name},'%') | |||
| </if> | |||
| @@ -54,18 +54,10 @@ | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| <select id="countByName" resultType="java.lang.Integer" parameterType="java.util.HashMap"> | |||
| select count(1) from mall_role where name=#{name} | |||
| <if test="id!=null"> and id !=#{id}</if> | |||
| </select> | |||
| <select id="findRoleByUserId" parameterType="java.lang.Long" resultMap="BaseResultMap"> | |||
| SELECT r.id | |||
| FROM mall_user_role u2r, mall_role r | |||
| WHERE u2r.role_id = r.id | |||
| AND u2r.uid = #{userId} | |||
| </select> | |||
| @@ -49,8 +49,9 @@ | |||
| </select> | |||
| <delete id="deleteByRoleId"> | |||
| delete from mall_user_role_permission where role_id=#{roleId} | |||
| </delete> | |||
| </mapper> | |||