新增登录时判断是否有系统权限,角色授权时清除缓存,新增部分权限注解
This commit is contained in:
@@ -1,24 +1,17 @@
|
||||
package com.hcframe.user.module.auth.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.common.WebPageInfo;
|
||||
import com.hcframe.redis.RedisUtil;
|
||||
import com.hcframe.user.module.auth.service.MenuService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
/**
|
||||
* @author wewe
|
||||
* @date 2021年4月13日
|
||||
@@ -28,15 +21,21 @@ import io.swagger.annotations.ApiOperation;
|
||||
@Api(tags = "功能级权限管理")
|
||||
@RequestMapping("menu")
|
||||
public class MenuController {
|
||||
|
||||
|
||||
@Autowired MenuService menuService;
|
||||
|
||||
|
||||
final RedisUtil redisUtil;
|
||||
|
||||
public MenuController(RedisUtil redisUtil) {
|
||||
this.redisUtil = redisUtil;
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增功能级权限", notes = "给后台传key-value对象模式即可")
|
||||
public ResultVO<Object> addMenu(@RequestParam Map<String, Object> data) {
|
||||
return menuService.addMenu(data);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除功能级权限", notes = "删除后关联表数据也会被删除")
|
||||
public ResultVO<Object> deleteMenu(@RequestParam List<Long> ids) {
|
||||
@@ -48,37 +47,38 @@ public class MenuController {
|
||||
public ResultVO<Integer> updateMenu(@RequestParam Map<String, Object> data, @PathVariable Integer version) {
|
||||
return menuService.updateMenu(data, version);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("list")
|
||||
@ApiOperation(value = "查询功能级权限列表")
|
||||
public ResultVO<PageInfo<Map<String, Object>>> getMenuList(String data, WebPageInfo webPageInfo) {
|
||||
return menuService.getMenuList(data, webPageInfo);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("addRole")
|
||||
@ApiOperation(value = "角色授权", notes = "roleId,menuIds,中间用逗号连接")
|
||||
public ResultVO<Object> addRoleMenu(@RequestParam Long roleId,@RequestParam List<String> menuIds) {
|
||||
redisUtil.del("auth");
|
||||
return menuService.addRoleMenu(roleId, menuIds);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("tree")
|
||||
@ApiOperation(value = "功能级权限树,根节点是业务系统")
|
||||
public ResultVO<Object> getMenuTree() {
|
||||
return menuService.getMenuTree();
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("selected")
|
||||
@ApiOperation(value = "获取当前角色已选中节点")
|
||||
public ResultVO<Object> getSelectedMenu(@RequestParam Long roleId) {
|
||||
return menuService.getSelectedMenu(roleId);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("checkPath")
|
||||
@ApiOperation(value = "校验PATH是否唯一", notes = "")
|
||||
public ResultVO<Object> checkPath(@RequestParam Map<String, Object> data) {
|
||||
return menuService.checkPath(data);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("oslist")
|
||||
@ApiOperation(value = "获取系统信息列表")
|
||||
public ResultVO<Object> getOsList() {
|
||||
|
||||
@@ -14,4 +14,20 @@ import java.util.Map;
|
||||
*/
|
||||
public interface AuthDao {
|
||||
List<Map<String,Object>> selectMenuList(OsSysMenu osSysMenu);
|
||||
|
||||
List<String> getUserRoleAuth(String userId);
|
||||
|
||||
List<String> getUserRoleGroupAuth(String userId);
|
||||
|
||||
List<String> getOrgRoleAuth(String orgCode);
|
||||
|
||||
List<String> getOrgGroupAuth(String orgCode);
|
||||
|
||||
Long getRoleOs(String userId);
|
||||
|
||||
Long getGroupOs(String userId);
|
||||
|
||||
Long getOrgOs(String orgCode);
|
||||
|
||||
Long getOrgGroupOs(String orgCode);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.hcframe.user.module.auth.mapper.impl;
|
||||
|
||||
import com.hcframe.base.module.auth.entity.OsSysMenu;
|
||||
import com.hcframe.base.module.data.module.BaseMapper;
|
||||
import com.hcframe.base.module.data.module.BaseMapperImpl;
|
||||
import com.hcframe.base.module.data.module.*;
|
||||
import com.hcframe.user.module.auth.mapper.AuthDao;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -27,8 +27,10 @@ public class AuthDaoImpl implements AuthDao {
|
||||
this.baseMapper = baseMapper;
|
||||
}
|
||||
|
||||
private static final Integer OS_ID = 8;
|
||||
|
||||
@Override
|
||||
public List<Map<String,Object>> selectMenuList(OsSysMenu osSysMenu) {
|
||||
public List<Map<String, Object>> selectMenuList(OsSysMenu osSysMenu) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(" SELECT OS_SYS_MENU.MENU_ID,\n" +
|
||||
" OS_SYS_MENU.MENU_NAME,\n" +
|
||||
@@ -67,4 +69,217 @@ public class AuthDaoImpl implements AuthDao {
|
||||
" OS_SYS_MENU.ORDER_NUM ASC");
|
||||
return baseMapper.selectSql(stringBuilder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUserRoleAuth(String userId) {
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_USER_ROLE")
|
||||
.field("OS_SYS_MENU.PATH")
|
||||
.join("OS_REL_ROLE_MENU")
|
||||
.on("ROLE_ID", "OS_REL_USER_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_MENU")
|
||||
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_USER_ROLE", "ROLE_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.MENU_STATUS", 1)
|
||||
.andEqual("OS_SYS_MENU.OS_ID", OS_ID)
|
||||
.andEqual("OS_REL_USER_ROLE.USER_ID", userId.replaceAll("\"", ""))
|
||||
.build();
|
||||
return getPaths(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUserRoleGroupAuth(String userId) {
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_USER_GROUP")
|
||||
.field("OS_SYS_MENU.PATH")
|
||||
.join("OS_SYS_ROLE_GROUP")
|
||||
.on("GROUP_ID", "OS_REL_USER_GROUP", "GROUP_ID")
|
||||
.join("OS_REL_GROUP_ROLE")
|
||||
.on("GROUP_ID", "OS_REL_USER_GROUP", "GROUP_ID")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_REL_ROLE_MENU")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_MENU")
|
||||
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.OS_ID", OS_ID)
|
||||
.andEqual("OS_SYS_MENU.MENU_STATUS", 1)
|
||||
.andEqual("OS_SYS_ROLE_GROUP.DELETED", 1)
|
||||
.andEqual("OS_REL_USER_GROUP.USER_ID", userId.replaceAll("\"", ""))
|
||||
.build();
|
||||
return getPaths(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOrgRoleAuth(String orgCode) {
|
||||
DataMap<Object> dataMap = DataMap.builder().tableName("GB_CAS_DEPT").fields("ID").build();
|
||||
Map<String, Object> org = baseMapper.selectOneByCondition(Condition.creatCriteria(dataMap).andEqual("CODE", orgCode).build());
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_DEPT_ROLE")
|
||||
.field("OS_SYS_MENU.PATH")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_DEPT_ROLE", "ROLE_ID")
|
||||
.join("OS_REL_ROLE_MENU")
|
||||
.on("ROLE_ID", "OS_REL_DEPT_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_MENU")
|
||||
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.OS_ID", OS_ID)
|
||||
.andEqual("OS_SYS_MENU.MENU_STATUS", 1)
|
||||
.andEqual("OS_REL_DEPT_ROLE.DEPT_ID", org.get("ID")).build();
|
||||
return getPaths(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOrgGroupAuth(String orgCode) {
|
||||
DataMap<Object> dataMap = DataMap.builder().tableName("GB_CAS_DEPT").fields("ID").build();
|
||||
Map<String, Object> org = baseMapper.selectOneByCondition(Condition.creatCriteria(dataMap).andEqual("CODE", orgCode).build());
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_DEPT_GROUP")
|
||||
.field("OS_SYS_MENU.PATH")
|
||||
.join("OS_SYS_ROLE_GROUP")
|
||||
.on("GROUP_ID", "OS_REL_DEPT_GROUP", "GROUP_ID")
|
||||
.join("OS_REL_GROUP_ROLE")
|
||||
.on("GROUP_ID", "OS_REL_DEPT_GROUP", "GROUP_ID")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_REL_ROLE_MENU")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_MENU")
|
||||
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.DELETED", 1)
|
||||
.andEqual("OS_SYS_ROLE_GROUP.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.OS_ID", OS_ID)
|
||||
.andEqual("OS_SYS_MENU.MENU_STATUS", 1)
|
||||
.andEqual("OS_REL_DEPT_GROUP.DEPT_ID", org.get("ID"))
|
||||
.build();
|
||||
return getPaths(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getRoleOs(String userId) {
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_USER_ROLE")
|
||||
.field("count(OS_SYS_OS.OS_CODE)")
|
||||
.join("OS_REL_ROLE_OS")
|
||||
.on("ROLE_ID", "OS_REL_ROLE_OS", "ROLE_ID")
|
||||
.join("OS_SYS_OS")
|
||||
.on("OS_ID", "OS_REL_ROLE_OS", "OS_ID")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_USER_ROLE", "ROLE_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_OS.DELETED", 1)
|
||||
.andEqual("OS_SYS_OS.ENABLED", 1)
|
||||
.andEqual("OS_SYS_OS.OS_ID", OS_ID)
|
||||
.andEqual("OS_REL_USER_ROLE.USER_ID", userId.replaceAll("\"", ""))
|
||||
.build();
|
||||
return baseMapper.count(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getGroupOs(String userId) {
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_USER_GROUP")
|
||||
.field("count(OS_SYS_OS.OS_CODE)")
|
||||
.join("OS_SYS_ROLE_GROUP")
|
||||
.on("GROUP_ID", "OS_REL_USER_GROUP", "GROUP_ID")
|
||||
.join("OS_REL_GROUP_ROLE")
|
||||
.on("GROUP_ID", "OS_REL_USER_GROUP", "GROUP_ID")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_REL_ROLE_OS")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_OS")
|
||||
.on("OS_ID", "OS_REL_ROLE_OS", "OS_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_OS.DELETED", 1)
|
||||
.andEqual("OS_SYS_OS.OS_ID", OS_ID)
|
||||
.andEqual("OS_SYS_OS.ENABLED", 1)
|
||||
.andEqual("OS_SYS_ROLE_GROUP.DELETED", 1)
|
||||
.andEqual("OS_REL_USER_GROUP.USER_ID", userId.replaceAll("\"", ""))
|
||||
.build();
|
||||
return baseMapper.count(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getOrgOs(String orgCode) {
|
||||
DataMap<Object> dataMap = DataMap.builder().tableName("GB_CAS_DEPT").fields("ID").build();
|
||||
Map<String, Object> org = baseMapper.selectOneByCondition(Condition.creatCriteria(dataMap).andEqual("CODE", orgCode).build());
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_DEPT_ROLE")
|
||||
.field("count(OS_SYS_OS.OS_CODE)")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_DEPT_ROLE", "ROLE_ID")
|
||||
.join("OS_REL_ROLE_OS")
|
||||
.on("ROLE_ID", "OS_REL_DEPT_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_OS")
|
||||
.on("OS_ID", "OS_REL_ROLE_OS", "OS_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_OS.DELETED", 1)
|
||||
.andEqual("OS_SYS_OS.OS_ID", OS_ID)
|
||||
.andEqual("OS_SYS_OS.ENABLED",1)
|
||||
.andEqual("OS_REL_DEPT_ROLE.DEPT_ID", org.get("ID")).build();
|
||||
return baseMapper.count(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getOrgGroupOs(String orgCode) {
|
||||
DataMap<Object> dataMap = DataMap.builder().tableName("GB_CAS_DEPT").fields("ID").build();
|
||||
Map<String, Object> org = baseMapper.selectOneByCondition(Condition.creatCriteria(dataMap).andEqual("CODE", orgCode).build());
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_DEPT_GROUP")
|
||||
.field("count(OS_SYS_OS.OS_CODE)")
|
||||
.join("OS_SYS_ROLE_GROUP")
|
||||
.on("GROUP_ID", "OS_REL_DEPT_GROUP", "GROUP_ID")
|
||||
.join("OS_REL_GROUP_ROLE")
|
||||
.on("GROUP_ID", "OS_REL_DEPT_GROUP", "GROUP_ID")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_REL_ROLE_OS")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_OS")
|
||||
.on("OS_ID", "OS_REL_ROLE_OS", "OS_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_OS.DELETED", 1)
|
||||
.andEqual("OS_SYS_ROLE_GROUP.DELETED", 1)
|
||||
.andEqual("OS_SYS_OS.OS_ID", OS_ID)
|
||||
.andEqual("OS_SYS_OS.ENABLED",1)
|
||||
.andEqual("OS_REL_DEPT_GROUP.DEPT_ID", org.get("ID"))
|
||||
.build();
|
||||
return baseMapper.count(condition);
|
||||
}
|
||||
|
||||
private List<String> getPaths(Condition condition) {
|
||||
List<Map<String, Object>> list = baseMapper.selectByCondition(condition);
|
||||
List<String> resultList = new ArrayList<>();
|
||||
if (list != null && list.size() > 0) {
|
||||
for (Map<String, Object> objectMap : list) {
|
||||
resultList.add(String.valueOf(objectMap.get("PATH")));
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,6 @@ public interface AuthService {
|
||||
|
||||
List<Map<String,Object>> getMenuResultList(OsSysMenu osSysMenu);
|
||||
|
||||
Long getUserOs(String userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -45,114 +45,24 @@ public class AuthServiceImpl implements AuthService {
|
||||
|
||||
@Override
|
||||
public List<String> getUserRoleAuth(String userId) {
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_USER_ROLE")
|
||||
.field("OS_SYS_MENU.PATH")
|
||||
.join("OS_REL_ROLE_MENU")
|
||||
.on("ROLE_ID", "OS_REL_USER_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_MENU")
|
||||
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_USER_ROLE", "ROLE_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.MENU_STATUS",1)
|
||||
.andEqual("OS_SYS_MENU.OS_ID", 8)
|
||||
.andEqual("OS_REL_USER_ROLE.USER_ID", userId.replaceAll("\"", ""))
|
||||
.build();
|
||||
return getPaths(condition);
|
||||
return authDao.getUserRoleAuth(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUserRoleGroupAuth(String userId) {
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_USER_GROUP")
|
||||
.field("OS_SYS_MENU.PATH")
|
||||
.join("OS_SYS_ROLE_GROUP")
|
||||
.on("GROUP_ID", "OS_REL_USER_GROUP", "GROUP_ID")
|
||||
.join("OS_REL_GROUP_ROLE")
|
||||
.on("GROUP_ID", "OS_REL_USER_GROUP", "GROUP_ID")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_REL_ROLE_MENU")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_MENU")
|
||||
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.OS_ID", 8)
|
||||
.andEqual("OS_SYS_MENU.MENU_STATUS",1)
|
||||
.andEqual("OS_SYS_ROLE_GROUP.DELETED", 1)
|
||||
.andEqual("OS_REL_USER_GROUP.USER_ID", userId.replaceAll("\"", ""))
|
||||
.build();
|
||||
return getPaths(condition);
|
||||
}
|
||||
return authDao.getUserRoleGroupAuth(userId);
|
||||
|
||||
private List<String> getPaths(Condition condition) {
|
||||
List<Map<String, Object>> list = baseMapper.selectByCondition(condition);
|
||||
List<String> resultList = new ArrayList<>();
|
||||
if (list != null && list.size() > 0) {
|
||||
for (Map<String, Object> objectMap : list) {
|
||||
resultList.add(String.valueOf(objectMap.get("PATH")));
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOrgRoleAuth(String orgCode) {
|
||||
DataMap<Object> dataMap = DataMap.builder().tableName("GB_CAS_DEPT").fields("ID").build();
|
||||
Map<String, Object> org = baseMapper.selectOneByCondition(Condition.creatCriteria(dataMap).andEqual("CODE", orgCode).build());
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_DEPT_ROLE")
|
||||
.field("OS_SYS_MENU.PATH")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_DEPT_ROLE", "ROLE_ID")
|
||||
.join("OS_REL_ROLE_MENU")
|
||||
.on("ROLE_ID", "OS_REL_DEPT_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_MENU")
|
||||
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.OS_ID", 8)
|
||||
.andEqual("OS_SYS_MENU.MENU_STATUS",1)
|
||||
.andEqual("OS_REL_DEPT_ROLE.DEPT_ID", org.get("ID")).build();
|
||||
return getPaths(condition);
|
||||
return authDao.getOrgRoleAuth(orgCode);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOrgGroupAuth(String orgCode) {
|
||||
DataMap<Object> dataMap = DataMap.builder().tableName("GB_CAS_DEPT").fields("ID").build();
|
||||
Map<String, Object> org = baseMapper.selectOneByCondition(Condition.creatCriteria(dataMap).andEqual("CODE", orgCode).build());
|
||||
SelectCondition selectCondition = SelectCondition
|
||||
.sqlJoinBuilder("OS_REL_DEPT_GROUP")
|
||||
.field("OS_SYS_MENU.PATH")
|
||||
.join("OS_SYS_ROLE_GROUP")
|
||||
.on("GROUP_ID", "OS_REL_DEPT_GROUP", "GROUP_ID")
|
||||
.join("OS_REL_GROUP_ROLE")
|
||||
.on("GROUP_ID", "OS_REL_DEPT_GROUP", "GROUP_ID")
|
||||
.join("OS_SYS_ROLE")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_REL_ROLE_MENU")
|
||||
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
|
||||
.join("OS_SYS_MENU")
|
||||
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
|
||||
.build();
|
||||
Condition condition = Condition.creatCriteria(selectCondition)
|
||||
.andEqual("OS_SYS_ROLE.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.DELETED", 1)
|
||||
.andEqual("OS_SYS_ROLE_GROUP.DELETED", 1)
|
||||
.andEqual("OS_SYS_MENU.OS_ID", 8)
|
||||
.andEqual("OS_SYS_MENU.MENU_STATUS",1)
|
||||
.andEqual("OS_REL_DEPT_GROUP.DEPT_ID", org.get("ID"))
|
||||
.build();
|
||||
return getPaths(condition);
|
||||
return authDao.getOrgGroupAuth(orgCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,15 +70,22 @@ public class AuthServiceImpl implements AuthService {
|
||||
Set<String> authSet = (Set<String>) redisUtil.hget("auth", userId);
|
||||
if (authSet == null) {
|
||||
Map<String, Object> user = baseMapper.selectByPk(DataMap.builder().tableName("GB_CAS_MEMBER").pkName("ID").pkValue(userId).build());
|
||||
if ("admin".equals(user.get("NAME"))) {
|
||||
if (user != null && "admin".equals(user.get("NAME"))) {
|
||||
authSet = getAllAuth();
|
||||
redisUtil.hset("auth", userId,authSet,24 * 3600);
|
||||
redisUtil.hset("auth", userId, authSet, 24 * 3600);
|
||||
return getAllAuth();
|
||||
}
|
||||
List<String> roleAuth = getUserRoleAuth(String.valueOf(user.get("ID")));
|
||||
List<String> groupAuth = getUserRoleAuth(String.valueOf(user.get("ID")));
|
||||
List<String> orgAui = getOrgRoleAuth(String.valueOf(user.get("DEPT_CODE")));
|
||||
List<String> orgGroupAuth = getOrgGroupAuth(String.valueOf(user.get("DEPT_CODE")));
|
||||
List<String> orgAui;
|
||||
List<String> orgGroupAuth;
|
||||
if (!org.springframework.util.StringUtils.isEmpty(user.get("DEPT_CODE"))) {
|
||||
orgAui = getOrgRoleAuth(String.valueOf(user.get("DEPT_CODE")));
|
||||
orgGroupAuth = getOrgGroupAuth(String.valueOf(user.get("DEPT_CODE")));
|
||||
} else {
|
||||
orgAui = new ArrayList<>();
|
||||
orgGroupAuth = new ArrayList<>();
|
||||
}
|
||||
List<String> orgGuobo = getOrgGroupAuth("guobo");
|
||||
List<String> orgGuoboGroup = getOrgGroupAuth("guobo");
|
||||
authSet = new HashSet<>(roleAuth);
|
||||
@@ -177,7 +94,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
authSet.addAll(orgGroupAuth);
|
||||
authSet.addAll(orgGuobo);
|
||||
authSet.addAll(orgGuoboGroup);
|
||||
if (String.valueOf(user.get("DEPT_CODE")).length() == 6) {
|
||||
if (!org.springframework.util.StringUtils.isEmpty(user.get("DEPT_CODE")) && String.valueOf(user.get("DEPT_CODE")).length() == 6) {
|
||||
String code = String.valueOf(user.get("DEPT_CODE"));
|
||||
code = code.substring(0, 4);
|
||||
List<String> orgAuiParent = getOrgGroupAuth(code);
|
||||
@@ -185,7 +102,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
authSet.addAll(orgAuiParent);
|
||||
authSet.addAll(orgGroupAuthParent);
|
||||
}
|
||||
redisUtil.hset("auth", userId,authSet,24 * 3600);
|
||||
redisUtil.hset("auth", userId, authSet, 24 * 3600);
|
||||
}
|
||||
return authSet;
|
||||
}
|
||||
@@ -247,7 +164,8 @@ public class AuthServiceImpl implements AuthService {
|
||||
}
|
||||
return tlist;
|
||||
}
|
||||
private boolean hasChild(List<OsSysMenu> list, OsSysMenu t) {
|
||||
|
||||
private boolean hasChild(List<OsSysMenu> list, OsSysMenu t) {
|
||||
return getChildList(list, t).size() > 0;
|
||||
}
|
||||
|
||||
@@ -298,11 +216,14 @@ public class AuthServiceImpl implements AuthService {
|
||||
|
||||
@Override
|
||||
public List<OsSysMenu> getUserMenuResult(Set<String> set) {
|
||||
if (set == null || set.size() == 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String str : set) {
|
||||
stringBuilder.append("'").append(str).append("'").append(",");
|
||||
}
|
||||
List<OsSysMenu> list=osSysMenuDao.selectMenuByUser(stringBuilder.substring(0, stringBuilder.length() - 1));
|
||||
List<OsSysMenu> list = osSysMenuDao.selectMenuByUser(stringBuilder.substring(0, stringBuilder.length() - 1));
|
||||
return getChildPerms(list, 0);
|
||||
}
|
||||
|
||||
@@ -312,11 +233,43 @@ public class AuthServiceImpl implements AuthService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String,Object>> getMenuResultList(OsSysMenu osSysMenu) {
|
||||
|
||||
public List<Map<String, Object>> getMenuResultList(OsSysMenu osSysMenu) {
|
||||
return authDao.selectMenuList(osSysMenu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getUserOs(String userId) {
|
||||
Map<String, Object> user = baseMapper.selectByPk("GB_CAS_MEMBER", "ID", userId.replaceAll("\"", ""));
|
||||
if (user != null && "admin".equals(user.get("NAME"))) {
|
||||
return baseMapper.count("OS_SYS_OS", Condition.creatCriteria().build());
|
||||
}
|
||||
Long count = 0L;
|
||||
count += getRoleOs(userId);
|
||||
count += getGroupOs(userId);
|
||||
if (!org.springframework.util.StringUtils.isEmpty(user.get("DEPT_CODE"))) {
|
||||
count += getOrgOs(String.valueOf(user.get("DEPT_CODE")));
|
||||
count += getOrgGroupOs(String.valueOf(user.get("DEPT_CODE")));
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public Long getRoleOs(String userId) {
|
||||
return authDao.getRoleOs(userId);
|
||||
}
|
||||
|
||||
public Long getGroupOs(String userId) {
|
||||
return authDao.getGroupOs(userId);
|
||||
}
|
||||
|
||||
public Long getOrgOs(String orgCode) {
|
||||
return authDao.getOrgOs(orgCode);
|
||||
|
||||
}
|
||||
|
||||
public Long getOrgGroupOs(String orgCode) {
|
||||
return authDao.getOrgGroupOs(orgCode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取路由名称
|
||||
@@ -364,7 +317,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
if (StringUtils.isNotEmpty(menu.getComponent()) && !isMeunFrame(menu)) {
|
||||
component = menu.getComponent();
|
||||
}
|
||||
if (StringUtils.isEmpty(menu.getComponent())&&isNotParentMenuFrame(menu)) {
|
||||
if (StringUtils.isEmpty(menu.getComponent()) && isNotParentMenuFrame(menu)) {
|
||||
component = AuthConstants.UN_LAYOUT;
|
||||
}
|
||||
return component;
|
||||
|
||||
@@ -2,17 +2,24 @@ package com.hcframe.user.module.manage.controller;
|
||||
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.redis.RedisUtil;
|
||||
import com.hcframe.user.module.auth.service.AuthService;
|
||||
import net.unicon.cas.client.configuration.CasClientConfigurationProperties;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.jasig.cas.client.authentication.AttributePrincipal;
|
||||
import org.jasig.cas.client.validation.AssertionImpl;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("cas")
|
||||
@@ -24,16 +31,20 @@ public class CasController {
|
||||
final
|
||||
CasClientConfigurationProperties casClientConfigurationProperties;
|
||||
|
||||
public CasController(RedisUtil redisUtil, CasClientConfigurationProperties casClientConfigurationProperties) {
|
||||
final AuthService authService;
|
||||
|
||||
public CasController(RedisUtil redisUtil,
|
||||
CasClientConfigurationProperties casClientConfigurationProperties,
|
||||
AuthService authService) {
|
||||
this.redisUtil = redisUtil;
|
||||
this.casClientConfigurationProperties = casClientConfigurationProperties;
|
||||
this.authService = authService;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("valid")
|
||||
public ResultVO<String> casValid(HttpServletResponse response, HttpServletRequest request,String webUrl) {
|
||||
String token = "";
|
||||
// token = request.getHeader("X-Access-Token");
|
||||
try {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
for (Cookie cookie : cookies) {
|
||||
@@ -43,8 +54,17 @@ public class CasController {
|
||||
break;
|
||||
}
|
||||
}
|
||||
webUrl = URLDecoder.decode(webUrl, "utf-8");
|
||||
response.sendRedirect("http://"+webUrl+"/#/?token=" + token );
|
||||
Map<Object, Object> hashMap = (Map<Object, Object>) redisUtil.hget("session", token);
|
||||
AssertionImpl assertion = (AssertionImpl) hashMap.get("_const_cas_assertion_");
|
||||
AttributePrincipal attributePrincipal = assertion.getPrincipal();
|
||||
Map<String, Object> user = attributePrincipal.getAttributes();
|
||||
Long count = authService.getUserOs(String.valueOf(user.get("ID")));
|
||||
if (count == 0) {
|
||||
response.sendRedirect("http://" + webUrl + "/#/?token=noAuth");
|
||||
} else {
|
||||
webUrl = URLDecoder.decode(webUrl, "utf-8");
|
||||
response.sendRedirect("http://" + webUrl + "/#/?token=" + token);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.hcframe.base.common.WebPageInfo;
|
||||
import com.hcframe.user.module.manage.service.ManageService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -52,6 +53,7 @@ public class ManageController {
|
||||
|
||||
@GetMapping()
|
||||
@ApiOperation(value = "获取用户列表" )
|
||||
@RequiresPermissions(value = {"userinfo","system:userManage:innerUser:list"},logical = Logical.OR)
|
||||
public ResultVO<PageInfo<Map<String,Object>>> getUserList(String data, WebPageInfo webPageInfo,String orgId) {
|
||||
return manageService.getUserList(data, webPageInfo,orgId);
|
||||
}
|
||||
@@ -64,7 +66,7 @@ public class ManageController {
|
||||
|
||||
@PutMapping("/resetPassword/{version}")
|
||||
@ApiOperation(value = "重置密码")
|
||||
@RequiresPermissions(value = { "systemManage" })
|
||||
@RequiresPermissions(value = { "systemManage","system:list" },logical = Logical.AND)
|
||||
public ResultVO<Integer> resetPassword(String userId,@PathVariable Integer version) {
|
||||
return manageService.resetPassword(userId,version);
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ public class ManageServiceDataImpl implements ManageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<Map<String,Object>> addUser(Map<String, Object> user) {
|
||||
JudgeException.isNull(user.get("PASSWORD"),"密码不能为空");
|
||||
JudgeException.isNull(user.get("LOGIN_NAME"),"用户名不能为空");
|
||||
public ResultVO<Map<String, Object>> addUser(Map<String, Object> user) {
|
||||
JudgeException.isNull(user.get("PASSWORD"), "密码不能为空");
|
||||
JudgeException.isNull(user.get("LOGIN_NAME"), "用户名不能为空");
|
||||
if (!StringUtils.isEmpty(user.get("ORG_ACCOUNT_ID"))) {
|
||||
String orgAcId = String.valueOf(user.get("ORG_ACCOUNT_ID"));
|
||||
user.put("ORG_ACCOUNT_ID", orgAcId.replaceAll("\"", ""));
|
||||
@@ -81,12 +81,12 @@ public class ManageServiceDataImpl implements ManageService {
|
||||
user.put("ORG_DEPARTMENT_ID", orgDeptId.replaceAll("\"", ""));
|
||||
}
|
||||
try {
|
||||
user.put("PASSWORD",MD5Utils.encode((String) user.get("PASSWORD")));
|
||||
user.put("PASSWORD", MD5Utils.encode((String) user.get("PASSWORD")));
|
||||
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
|
||||
logger.error("新增用户失败",e);
|
||||
logger.error("新增用户失败", e);
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
return tableService.saveWithDate(TABLE_INFO,user);
|
||||
return tableService.saveWithDate(TABLE_INFO, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,27 +100,27 @@ public class ManageServiceDataImpl implements ManageService {
|
||||
String orgDeptId = String.valueOf(user.get("ORG_DEPARTMENT_ID"));
|
||||
user.put("ORG_DEPARTMENT_ID", orgDeptId.replaceAll("\"", ""));
|
||||
}
|
||||
return tableService.updateWithDate(TABLE_INFO,user,version);
|
||||
return tableService.updateWithDate(TABLE_INFO, user, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<Integer> deleteUser(String ids) {
|
||||
return tableService.logicDelete(TABLE_INFO,ids);
|
||||
return tableService.logicDelete(TABLE_INFO, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<PageInfo<Map<String, Object>>> getUserList(String data, WebPageInfo webPageInfo, String orgId) {
|
||||
DataMap<Object> dataMap = DataMap.builder().sysOsTable(TABLE_INFO).build();
|
||||
Condition.ConditionBuilder builder = Condition.creatCriteria(dataMap);
|
||||
if (!StringUtils.isEmpty(orgId)&&!orgId.equals("guobo")) {
|
||||
if (!StringUtils.isEmpty(orgId) && !orgId.equals("guobo")) {
|
||||
orgId = orgId.replaceAll("\"", "");
|
||||
String sql = "select CODE from GB_CAS_DEPT where CODE like '"+orgId+"%'";
|
||||
String sql = "select CODE from GB_CAS_DEPT where CODE like '" + orgId + "%'";
|
||||
List<Map<String, Object>> list = baseMapper.selectSql(sql);
|
||||
List<Object> idList = new ArrayList<>();
|
||||
for (Map<String, Object> code : list) {
|
||||
idList.add(code.get("CODE"));
|
||||
}
|
||||
builder.andIn("DEPT_CODE",idList);
|
||||
builder.andIn("DEPT_CODE", idList);
|
||||
}
|
||||
builder.andEqual("USER_TYPE", "GN");
|
||||
if (!StringUtils.isEmpty(data)) {
|
||||
@@ -133,8 +133,8 @@ public class ManageServiceDataImpl implements ManageService {
|
||||
builder = tableService.getQueryBuilder(jsonArray, builder);
|
||||
}
|
||||
builder.andEqual("DELETED", 1);
|
||||
PageInfo<Map<String,Object>> page = baseMapper.selectByCondition(builder.build(), webPageInfo);
|
||||
List<Map<String,Object>> list = page.getList();
|
||||
PageInfo<Map<String, Object>> page = baseMapper.selectByCondition(builder.build(), webPageInfo);
|
||||
List<Map<String, Object>> list = page.getList();
|
||||
for (Map<String, Object> map : list) {
|
||||
map.remove("PASSWORD");
|
||||
map.put("PASSWORD", "******");
|
||||
@@ -146,14 +146,14 @@ public class ManageServiceDataImpl implements ManageService {
|
||||
@Override
|
||||
public ResultVO<Integer> resetPassword(String userId, Integer version) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put(PK_ID, userId.replaceAll("\"",""));
|
||||
map.put(PK_ID, userId.replaceAll("\"", ""));
|
||||
try {
|
||||
map.put("PASSWORD",MD5Utils.encode("123456"));
|
||||
map.put("PASSWORD", MD5Utils.encode("123456"));
|
||||
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
|
||||
logger.error("重置密码失败",e);
|
||||
logger.error("重置密码失败", e);
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
return tableService.updateWithDate(TABLE_INFO,map,version);
|
||||
return tableService.updateWithDate(TABLE_INFO, map, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -161,7 +161,7 @@ public class ManageServiceDataImpl implements ManageService {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put(PK_ID, userId);
|
||||
map.put("DISABLED", enabled);
|
||||
return tableService.updateWithDate(TABLE_INFO,map,version);
|
||||
return tableService.updateWithDate(TABLE_INFO, map, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,15 +180,15 @@ public class ManageServiceDataImpl implements ManageService {
|
||||
cell = row.getCell(4);
|
||||
String title = cell.getStringCellValue();
|
||||
List<Map<String, Object>> list = manageMapper.selectPersonList(name, department);
|
||||
if (list != null&&list.size()>0) {
|
||||
System.out.println(name+":"+list.get(0).get("ID"));
|
||||
System.out.println(name+":"+list.get(0).get("ID"));
|
||||
if (list != null && list.size() > 0) {
|
||||
System.out.println(name + ":" + list.get(0).get("ID"));
|
||||
System.out.println(name + ":" + list.get(0).get("ID"));
|
||||
String str = date.substring(date.indexOf(".") + 1, date.length());
|
||||
if (str.equals("1")) {
|
||||
date = date + "0";
|
||||
}
|
||||
System.out.println(date.trim()+".01 00:00:00");
|
||||
Date date1 = DateUtil.StringFormat(date.trim()+".01 00:00:00","yyyy.MM.dd HH:mm:ss");
|
||||
System.out.println(date.trim() + ".01 00:00:00");
|
||||
Date date1 = DateUtil.StringFormat(date.trim() + ".01 00:00:00", "yyyy.MM.dd HH:mm:ss");
|
||||
for (Map<String, Object> map : list) {
|
||||
map.put("TIME_TO_WORK", date1);
|
||||
map.put("TITLE_NAME", title);
|
||||
@@ -199,41 +199,33 @@ public class ManageServiceDataImpl implements ManageService {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<Integer> changePassword(String pwd, String npwd, String npwd2) {
|
||||
|
||||
JudgeException.isNull(pwd,"密码不能为空");
|
||||
JudgeException.isNull(npwd,"新密码不能为空");
|
||||
|
||||
if(!npwd.equals(npwd2)) {
|
||||
return ResultVO.getFailed("两次新密码输入不一致");
|
||||
}
|
||||
|
||||
Map<String, Object> user = (Map<String, Object>) SecurityUtils.getSubject().getPrincipal();
|
||||
|
||||
String id = (String) user.get("ID");
|
||||
|
||||
Map<String, Object> data = baseMapper.selectByPk(TABLE_NAME,PK_ID,id);
|
||||
@Override
|
||||
public ResultVO<Integer> changePassword(String pwd, String npwd, String npwd2) {
|
||||
JudgeException.isNull(pwd, "密码不能为空");
|
||||
JudgeException.isNull(npwd, "新密码不能为空");
|
||||
if (!npwd.equals(npwd2)) {
|
||||
return ResultVO.getFailed("两次新密码输入不一致");
|
||||
}
|
||||
Map<String, Object> user = (Map<String, Object>) SecurityUtils.getSubject().getPrincipal();
|
||||
String id = (String) user.get("ID");
|
||||
Map<String, Object> data = baseMapper.selectByPk(TABLE_NAME, PK_ID, id);
|
||||
Integer version = Integer.parseInt(data.get(FieldConstants.VERSION.toString()).toString());
|
||||
|
||||
try {
|
||||
if(!data.get("PASSWORD").equals(MD5Utils.encode(pwd))) {
|
||||
return ResultVO.getFailed("原密码错误");
|
||||
}
|
||||
if (!data.get("PASSWORD").equals(MD5Utils.encode(pwd))) {
|
||||
return ResultVO.getFailed("原密码错误");
|
||||
}
|
||||
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
|
||||
logger.error("验证密码失败",e);
|
||||
logger.error("验证密码失败", e);
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
|
||||
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put(PK_ID, id);
|
||||
try {
|
||||
map.put("PASSWORD",MD5Utils.encode(npwd));
|
||||
map.put("PASSWORD", MD5Utils.encode(npwd));
|
||||
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
|
||||
logger.error("重置密码失败",e);
|
||||
logger.error("重置密码失败", e);
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
return tableService.updateWithDate(TABLE_INFO,map,version);
|
||||
}
|
||||
return tableService.updateWithDate(TABLE_INFO, map, version);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user