Commit d98d3d6c authored by 廖旭伟's avatar 廖旭伟

Merge remote-tracking branch 'origin/master'

parents 4985c6ac 3028e9b1
This diff is collapsed.
...@@ -110,5 +110,24 @@ public class MenuController extends BaseCRUDJsonBodyMappingController<MenuServic ...@@ -110,5 +110,24 @@ public class MenuController extends BaseCRUDJsonBodyMappingController<MenuServic
return ret.toJSONString(); return ret.toJSONString();
} }
/**
* 查询所有可用菜单(树)
*/
@PostMapping(value = "findAll")
public String findAll() {
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
try {
List<MenuEntity> menuEntityList = this.service.findAllEnable();
ret.put(KEY_RESULT_DATA,menuEntityList);
} catch (Exception e) {
log.error("更新错误", e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, e.getMessage());
}
return ret.toJSONString();
}
} }
\ No newline at end of file
...@@ -15,7 +15,7 @@ import com.mortals.xhx.module.role.model.RoleAuthQuery; ...@@ -15,7 +15,7 @@ import com.mortals.xhx.module.role.model.RoleAuthQuery;
public interface RoleAuthService extends ICRUDService<RoleAuthEntity, Long> { public interface RoleAuthService extends ICRUDService<RoleAuthEntity, Long> {
/** /**
* 角色分配资源 * 角色分配菜单资源
*/ */
void doDistributionSource(RoleAuthQuery query); void assignMenu(RoleAuthQuery query);
} }
\ No newline at end of file
...@@ -12,7 +12,10 @@ import com.mortals.xhx.module.role.model.RoleUserQuery; ...@@ -12,7 +12,10 @@ import com.mortals.xhx.module.role.model.RoleUserQuery;
* @date 2022-05-25 * @date 2022-05-25
*/ */
public interface RoleUserService extends ICRUDService<RoleUserEntity,Long>{ public interface RoleUserService extends ICRUDService<RoleUserEntity,Long>{
void doDistributionUser(RoleUserQuery query);
void doDistributionRole(RoleUserQuery query); /**
* 给用户分配角色
* @param query
*/
void assignRoleToUser(RoleUserQuery query);
} }
\ No newline at end of file
...@@ -3,37 +3,57 @@ package com.mortals.xhx.module.role.service.impl; ...@@ -3,37 +3,57 @@ package com.mortals.xhx.module.role.service.impl;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.menu.model.MenuEntity;
import com.mortals.xhx.module.menu.model.MenuQuery;
import com.mortals.xhx.module.menu.service.MenuService;
import com.mortals.xhx.module.role.dao.RoleAuthDao; import com.mortals.xhx.module.role.dao.RoleAuthDao;
import com.mortals.xhx.module.role.model.RoleAuthEntity; import com.mortals.xhx.module.role.model.RoleAuthEntity;
import com.mortals.xhx.module.role.model.RoleAuthQuery; import com.mortals.xhx.module.role.model.RoleAuthQuery;
import com.mortals.xhx.module.role.service.RoleAuthService; import com.mortals.xhx.module.role.service.RoleAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap; import java.util.stream.Collectors;
import java.util.List;
import java.util.Map;
@Service("roleAuthService") @Service("roleAuthService")
public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, RoleAuthEntity, Long> implements RoleAuthService { public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, RoleAuthEntity, Long> implements RoleAuthService {
@Autowired
private MenuService menuService;
@Override @Override
public void doDistributionSource(RoleAuthQuery query) { public void assignMenu(RoleAuthQuery query) {
// 删除角色资源老数据 Map<Long, MenuEntity> menuEntityMap = menuService.find(new MenuQuery()).stream().collect(Collectors.toMap(x -> x.getId(), y -> y));
// 删除角色菜单资源老数据
Long roleId = query.getRoleId(); Long roleId = query.getRoleId();
Map<String, Object> condition = new HashMap<>(); Map<String, Object> condition = new HashMap<>();
condition.put("roleId", roleId); condition.put("roleId", roleId);
this.dao.delete(condition); this.dao.delete(condition);
List<RoleAuthEntity> list = new ArrayList<>(); Set<Long> curSet = query.getMenuIdList().stream().collect(Collectors.toSet());
// for (Long sourceId : query.getResourceIdList()) { query.getMenuIdList().stream().forEach(item -> {
// RoleAuthEntity entity = new RoleAuthEntity(); buildMenus(curSet, menuEntityMap.get(item), menuEntityMap);
// entity.setRoleId(roleId); });
// entity.setResourceId(sourceId); List<RoleAuthEntity> list = curSet.stream().map(item -> {
// list.add(entity); RoleAuthEntity entity = new RoleAuthEntity();
// } entity.setRoleId(roleId);
this.dao.insertBatch(list); entity.setMenuId(item);
return entity;
}).collect(Collectors.toList());
this.save(list);
}
private void buildMenus(Set<Long> curSet, MenuEntity menuEntity, Map<Long, MenuEntity> menuEntityMap) {
if (!ObjectUtils.isEmpty(menuEntity)) {
if (!curSet.contains(menuEntity.getId())) {
curSet.add(menuEntity.getId());
}
if (!ObjectUtils.isEmpty(menuEntity.getParentId())) {
buildMenus(curSet, menuEntityMap.get(menuEntity.getParentId()), menuEntityMap);
}
}
} }
} }
\ No newline at end of file
...@@ -25,31 +25,14 @@ import java.util.Map; ...@@ -25,31 +25,14 @@ import java.util.Map;
public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, RoleUserEntity,Long> implements RoleUserService { public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, RoleUserEntity,Long> implements RoleUserService {
@Override @Override
public void doDistributionUser(RoleUserQuery query) { public void assignRoleToUser(RoleUserQuery query) {
Long roleId = query.getRoleId(); //删除当前用户所有关联角色
// 删除角色对应的用户信息
Map<String, Object> condition = new HashMap<>(1);
condition.put("roleId", roleId);
dao.delete(condition);
List<Long> userIdList = query.getUserIdList();
List<RoleUserEntity> list = new ArrayList<>();
for (Long userId : userIdList) {
RoleUserEntity rolseUser = new RoleUserEntity();
rolseUser.setRoleId(roleId);
rolseUser.setUserId(userId);
list.add(rolseUser);
}
this.dao.insertBatch(list);
}
@Override
public void doDistributionRole(RoleUserQuery query) {
// 删除角色对应的用户信息
Long userId = query.getUserId(); Long userId = query.getUserId();
Map<String, Object> condition = new HashMap<>(1); Map<String, Object> condition = new HashMap<>(1);
condition.put("userId", userId); condition.put("userId", userId);
dao.delete(condition); dao.delete(condition);
//新增用户角色
List<Long> roleIdList = query.getRoleIdList(); List<Long> roleIdList = query.getRoleIdList();
List<RoleUserEntity> list = new ArrayList<>(); List<RoleUserEntity> list = new ArrayList<>();
for (Long roleId : roleIdList) { for (Long roleId : roleIdList) {
...@@ -58,7 +41,7 @@ public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, Ro ...@@ -58,7 +41,7 @@ public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, Ro
rolseUser.setUserId(userId); rolseUser.setUserId(userId);
list.add(rolseUser); list.add(rolseUser);
} }
this.dao.insertBatch(list); this.save(list);
} }
} }
\ No newline at end of file
...@@ -38,12 +38,12 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu ...@@ -38,12 +38,12 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu
} }
/** /**
* 分配菜单 * 分配菜单到角色
*/ */
@PostMapping(value = "distributionSource") @PostMapping(value = "assignMenuToRole")
public String distributionUser(@RequestBody RoleAuthQuery query) { public String assignMenuToRole(@RequestBody RoleAuthQuery query) {
try { try {
service.doDistributionSource(query); service.assignMenu(query);
JSONObject ret = new JSONObject(); JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS); ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString(); return ret.toJSONString();
......
...@@ -55,4 +55,24 @@ public class RoleUserController extends BaseCRUDJsonBodyMappingController<RoleUs ...@@ -55,4 +55,24 @@ public class RoleUserController extends BaseCRUDJsonBodyMappingController<RoleUs
} }
/**
* 给用户分配角色
*/
@PostMapping(value = "assignRoleToUser")
public String assignRoleToUser(@RequestBody RoleUserQuery query) {
JSONObject ret = new JSONObject();
try {
this.service.assignRoleToUser(query);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "分配角色成功!");
recordSysLog(request, getCurUser(), "分配角色成功!");
return ret.toJSONString();
} catch (Exception e) {
log.error("分配角色错误", e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
} }
\ No newline at end of file
...@@ -48,6 +48,4 @@ public class UserVo extends BaseEntityLong { ...@@ -48,6 +48,4 @@ public class UserVo extends BaseEntityLong {
/** 查询条件 */ /** 查询条件 */
private String query; private String query;
/** 角色id */
private Long roleId;
} }
\ No newline at end of file
...@@ -6,7 +6,8 @@ Content-Type: application/json ...@@ -6,7 +6,8 @@ Content-Type: application/json
{ {
"page":1, "page":1,
"size":10 "size":10,
"parentId":2
} }
...@@ -47,5 +48,9 @@ Authorization: {{authToken}} ...@@ -47,5 +48,9 @@ Authorization: {{authToken}}
Accept: application/json Accept: application/json
###菜单信息业务列表
POST {{baseUrl}}/menu/findAll
Authorization: {{authToken}}
Content-Type: application/json
...@@ -10,6 +10,17 @@ Content-Type: application/json ...@@ -10,6 +10,17 @@ Content-Type: application/json
} }
###分配菜单到角色
POST {{baseUrl}}/role/auth/assignMenuToRole
Authorization: {{authToken}}
Content-Type: application/json
{
"roleId":2,
"menuIdList":[2]
}
###角色菜单权限关联更新与保存 ###角色菜单权限关联更新与保存
POST {{baseUrl}}/role/auth/save POST {{baseUrl}}/role/auth/save
Authorization: {{authToken}} Authorization: {{authToken}}
......
...@@ -10,6 +10,17 @@ Content-Type: application/json ...@@ -10,6 +10,17 @@ Content-Type: application/json
} }
###分配用户到角色
POST {{baseUrl}}/role/user/assignRoleToUser
Authorization: {{authToken}}
Content-Type: application/json
{
"userId":1,
"roleIdList":[1,2]
}
###角色用户关联更新与保存 ###角色用户关联更新与保存
POST {{baseUrl}}/role/user/save POST {{baseUrl}}/role/user/save
Authorization: {{authToken}} Authorization: {{authToken}}
......
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