Commit 2fe69a17 authored by sml's avatar sml

代码提交

parent b8dc5470
...@@ -11,6 +11,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; ...@@ -11,6 +11,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import com.alibaba.fastjson.JSONObject;
import com.jz.dmp.modules.model.DmpMember; import com.jz.dmp.modules.model.DmpMember;
import com.jz.dmp.modules.model.DmpPermission; import com.jz.dmp.modules.model.DmpPermission;
import com.jz.dmp.modules.model.DmpRole; import com.jz.dmp.modules.model.DmpRole;
...@@ -32,6 +33,9 @@ public class CustomUserService implements UserDetailsService { ...@@ -32,6 +33,9 @@ public class CustomUserService implements UserDetailsService {
@Autowired @Autowired
DmpPermissionService dmpPermissionService; DmpPermissionService dmpPermissionService;
/**
*
*/
@Override @Override
public UserDetails loadUserByUsername(String userName) { public UserDetails loadUserByUsername(String userName) {
DmpMember user = null; DmpMember user = null;
...@@ -59,10 +63,14 @@ public class CustomUserService implements UserDetailsService { ...@@ -59,10 +63,14 @@ public class CustomUserService implements UserDetailsService {
//设置用户资源 //设置用户资源
List<DmpPermission> permissions = new ArrayList<DmpPermission>(); List<DmpPermission> permissions = new ArrayList<DmpPermission>();
if (!CollectionUtils.isEmpty(memberPermissions)) { if (!CollectionUtils.isEmpty(memberPermissions)) {
permissions.addAll(memberPermissions); String jsonStr = JSONObject.toJSONString(memberPermissions);
List<DmpPermission> list = JSONObject.parseArray(jsonStr, DmpPermission.class);
permissions.addAll(list);
} }
if (!CollectionUtils.isEmpty(memberProjPermissions)) { if (!CollectionUtils.isEmpty(memberProjPermissions)) {
permissions.addAll(memberProjPermissions); String jsonStr = JSONObject.toJSONString(memberProjPermissions);
List<DmpPermission> list = JSONObject.parseArray(jsonStr, DmpPermission.class);
permissions.addAll(list);
} }
user.setPermissionList(permissions); user.setPermissionList(permissions);
......
...@@ -3,7 +3,7 @@ package com.jz.dmp.config; ...@@ -3,7 +3,7 @@ package com.jz.dmp.config;
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component //@Component
public class SecurityInitializer extends AbstractSecurityWebApplicationInitializer { public class SecurityInitializer extends AbstractSecurityWebApplicationInitializer {
public SecurityInitializer() { public SecurityInitializer() {
......
...@@ -2,6 +2,7 @@ package com.jz.dmp.modules.controller.sys; ...@@ -2,6 +2,7 @@ package com.jz.dmp.modules.controller.sys;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -166,11 +167,11 @@ public class DmpPermissionController { ...@@ -166,11 +167,11 @@ public class DmpPermissionController {
@ApiImplicitParam(name = "parentCode", value = "父资源编码"), @ApiImplicitParam(name = "parentCode", value = "父资源编码"),
@ApiImplicitParam(name = "type", value = "请求类型:0:用户项目下资源;1:用户系统级别资源") @ApiImplicitParam(name = "type", value = "请求类型:0:用户项目下资源;1:用户系统级别资源")
}) })
public BaseBeanResponse<DmpPermissionDto> findListByParentCode(@RequestParam(name = "parentCode", required = true) String parentCode, @RequestParam(name = "type", required = true) String type, HttpServletRequest httpRequest){ public BaseBeanResponse<Map<String, Object>> findListByParentCode(@RequestParam(name = "parentCode", required = true) String parentCode, @RequestParam(name = "type", required = true) String type, HttpServletRequest httpRequest){
BaseBeanResponse<DmpPermissionDto> baseBeanResponse = new BaseBeanResponse<DmpPermissionDto>(); BaseBeanResponse<Map<String, Object>> baseBeanResponse = new BaseBeanResponse<Map<String, Object>>();
try { try {
baseBeanResponse = dmpPermissionService.findListByParentCode(parentCode, type, httpRequest); baseBeanResponse = dmpPermissionService.findUserAndPremissionByParentCode(parentCode, type, httpRequest);
} catch (Exception e) { } catch (Exception e) {
baseBeanResponse.setMessage("查询失败"); baseBeanResponse.setMessage("查询失败");
baseBeanResponse.setCode(StatuConstant.FAILURE_CODE); baseBeanResponse.setCode(StatuConstant.FAILURE_CODE);
......
...@@ -19,6 +19,11 @@ import com.fasterxml.jackson.annotation.JsonFormat; ...@@ -19,6 +19,11 @@ import com.fasterxml.jackson.annotation.JsonFormat;
*/ */
@ApiModel(value = "用户表", description = "用户表") @ApiModel(value = "用户表", description = "用户表")
public class DmpMember implements UserDetails{ public class DmpMember implements UserDetails{
/**
*
*/
private static final long serialVersionUID = -7755162995496909499L;
/** /**
* 用户ID * 用户ID
*/ */
......
package com.jz.dmp.modules.service.sys; package com.jz.dmp.modules.service.sys;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -102,5 +103,18 @@ public interface DmpPermissionService { ...@@ -102,5 +103,18 @@ public interface DmpPermissionService {
*/ */
public BaseBeanResponse<DmpPermissionDto> findListByParentCode(String parentCode, public BaseBeanResponse<DmpPermissionDto> findListByParentCode(String parentCode,
String type, HttpServletRequest httpRequest)throws Exception; String type, HttpServletRequest httpRequest)throws Exception;
/**
* @Title: findUserAndPremissionByParentCode
* @Description: TODO(根据父编码)
* @param @param parentCode
* @param @param httpRequest
* @param @return
* @param @throws Exception 参数
* @return BaseBeanResponse<DmpPermissionDto> 返回类型
* @throws
*/
public BaseBeanResponse<Map<String, Object>> findUserAndPremissionByParentCode(String parentCode,
String type, HttpServletRequest httpRequest)throws Exception;
} }
...@@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.jz.common.bean.BaseBeanResponse; import com.jz.common.bean.BaseBeanResponse;
...@@ -469,10 +470,14 @@ public class DmpMemberServiceImpl extends BaseService implements DmpMemberServic ...@@ -469,10 +470,14 @@ public class DmpMemberServiceImpl extends BaseService implements DmpMemberServic
List<DmpPermission> permissions = new ArrayList<DmpPermission>(); List<DmpPermission> permissions = new ArrayList<DmpPermission>();
if (!CollectionUtils.isEmpty(memberProjPermissions)) { if (!CollectionUtils.isEmpty(memberProjPermissions)) {
permissions.addAll(memberProjPermissions); String jsonStr = JSONObject.toJSONString(memberProjPermissions);
List<DmpPermission> list = JSONObject.parseArray(jsonStr, DmpPermission.class);
permissions.addAll(list);
} }
if (!CollectionUtils.isEmpty(member.getMemberPermissionList())) { if (!CollectionUtils.isEmpty(member.getMemberPermissionList())) {
permissions.addAll(member.getMemberPermissionList()); String jsonStr = JSONObject.toJSONString(member.getMemberPermissionList());
List<DmpPermission> list = JSONObject.parseArray(jsonStr, DmpPermission.class);
permissions.addAll(list);
} }
member.setPermissionList(permissions); member.setPermissionList(permissions);
......
...@@ -392,4 +392,57 @@ public class DmpPermissionServiceImpl extends BaseService implements DmpPermissi ...@@ -392,4 +392,57 @@ public class DmpPermissionServiceImpl extends BaseService implements DmpPermissi
return baseBeanResponse; return baseBeanResponse;
} }
/**
*获取父资源编码下当前用户项目所有资源
*/
@Override
public BaseBeanResponse<Map<String, Object>> findUserAndPremissionByParentCode(String parentCode,
String type, HttpServletRequest httpRequest) throws Exception {
Map<String, Object> resultMap = new HashMap<String, Object>();
BaseBeanResponse<Map<String, Object>> baseBeanResponse = new BaseBeanResponse<>();
//获取当前用户拥有的项目角色
DmpMember currentUser = SessionUtils.getSecurityUser();
if (currentUser==null) {
baseBeanResponse.setCode(StatuConstant.CODE_NOT_SIGNED);
baseBeanResponse.setMessage("用户未登录!");
return baseBeanResponse;
}
resultMap.put("user", currentUser);
List<DmpPermission> dmpPermissions = new ArrayList<DmpPermission>();
if ("0".equals(type)) {
dmpPermissions = dmpPermissionMapper.findByRoles(currentUser.getMemberProjectRoleList());
}else if("1".equals(type)) {
dmpPermissions = dmpPermissionMapper.findByRoles(currentUser.getMemberRoleList());
}else {
List<DmpPermission> list1 = dmpPermissionMapper.findByRoles(currentUser.getMemberProjectRoleList());
List<DmpPermission> list2 = dmpPermissionMapper.findByRoles(currentUser.getMemberRoleList());
List<DmpPermission> permissions = new ArrayList<DmpPermission>();
if (!CollectionUtils.isEmpty(list1)) {
permissions.addAll(list1);
}
if (!CollectionUtils.isEmpty(list2)) {
permissions.addAll(list2);
}
dmpPermissions = permissions;
}
//整理资源为树形结构
List<DmpPermission> permissions = permissionArrangeTree(parentCode, dmpPermissions);
List<DmpPermissionDto> list = MyDmpPermissionConverter.INSTANCE().domain2dto(permissions);
resultMap.put("permissions", list);
baseBeanResponse.setCode(StatuConstant.CODE_SUCCESS);
baseBeanResponse.setMessage("查询成功");
baseBeanResponse.setData(resultMap);
return baseBeanResponse;
}
} }
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from dmp_permission from dmp_permission
where permission_id = #{permissionId,jdbcType=INTEGER} where permission_id = #{permissionId,jdbcType=INTEGER}
AND data_status='1'
</select> </select>
<!-- 根据主键删除资源表 --> <!-- 根据主键删除资源表 -->
...@@ -304,6 +305,7 @@ ...@@ -304,6 +305,7 @@
<include refid="BaseDto_Column_List" /> <include refid="BaseDto_Column_List" />
from dmp_permission from dmp_permission
where permission_id = #{permissionId,jdbcType=INTEGER} where permission_id = #{permissionId,jdbcType=INTEGER}
AND data_status='1'
</select> </select>
<!-- 根据角色获取所有资源 --> <!-- 根据角色获取所有资源 -->
...@@ -314,16 +316,16 @@ ...@@ -314,16 +316,16 @@
permission.create_user_id, permission.create_time, permission.update_user_id, permission.update_time permission.create_user_id, permission.create_time, permission.update_user_id, permission.update_time
from dmp_permission permission from dmp_permission permission
left join dmp_role_permission rolePermission on permission.permission_id=rolePermission.permission_id left join dmp_role_permission rolePermission on permission.permission_id=rolePermission.permission_id
where where permission.data_status='1'
<choose> <choose>
<when test="dmpRoles.size>0"> <when test="dmpRoles.size>0">
rolePermission.role_id in AND rolePermission.role_id in
<foreach collection="dmpRoles" item="item" index="index" open="(" separator ="," close=")"> <foreach collection="dmpRoles" item="item" index="index" open="(" separator ="," close=")">
#{item.roleId,jdbcType=INTEGER} #{item.roleId,jdbcType=INTEGER}
</foreach> </foreach>
</when> </when>
<otherwise> <otherwise>
1 <![CDATA[ <> ]]> 1 AND 1 <![CDATA[ <> ]]> 1
</otherwise> </otherwise>
</choose> </choose>
</select> </select>
...@@ -333,7 +335,7 @@ ...@@ -333,7 +335,7 @@
SELECT SELECT
<include refid="BaseDto_Column_List"/> <include refid="BaseDto_Column_List"/>
FROM dmp_permission FROM dmp_permission
WHERE permission_url IS NOT NULL WHERE permission_url IS NOT NULL AND data_status='1'
</select> </select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment