Commit e1f98e2a authored by 赵啸非's avatar 赵啸非

Merge remote-tracking branch 'origin/master'

parents 21c3eab8 ae1bd709
This diff is collapsed.
...@@ -14,11 +14,13 @@ public class MenuNodeVO implements Serializable { ...@@ -14,11 +14,13 @@ public class MenuNodeVO implements Serializable {
private Long nodeId; private Long nodeId;
private Long parentId; private Long parentId;
private List<MenuNodeVO> childList; private List<MenuNodeVO> childList;
private Integer nodeType;
public MenuNodeVO(String nodeName, Long nodeId, Long parentId) { public MenuNodeVO(String nodeName, Long nodeId, Long parentId,Integer nodeType) {
this.nodeName = nodeName; this.nodeName = nodeName;
this.nodeId = nodeId; this.nodeId = nodeId;
this.parentId = parentId; this.parentId = parentId;
this.nodeType = nodeType;
} }
public void addChild(MenuNodeVO node){ public void addChild(MenuNodeVO node){
......
...@@ -270,7 +270,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity ...@@ -270,7 +270,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
List<MenuEntity> menuEntityList = this.find(query); List<MenuEntity> menuEntityList = this.find(query);
List<MenuNodeVO> nodeList = new ArrayList<>(); List<MenuNodeVO> nodeList = new ArrayList<>();
for (MenuEntity menuEntity:menuEntityList){ for (MenuEntity menuEntity:menuEntityList){
MenuNodeVO nodeVO = new MenuNodeVO(menuEntity.getName(),menuEntity.getId(),menuEntity.getParentId()); MenuNodeVO nodeVO = new MenuNodeVO(menuEntity.getName(),menuEntity.getId(),menuEntity.getParentId(),3);
nodeList.add(nodeVO); nodeList.add(nodeVO);
} }
List<MenuNodeVO> tree = creatMenuNodeTree(nodeList); List<MenuNodeVO> tree = creatMenuNodeTree(nodeList);
...@@ -303,7 +303,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity ...@@ -303,7 +303,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
List<ModelFeignVO> modelFeignVOS = JSONObject.parseArray(apiResp.getData().get("data").toString(),ModelFeignVO.class); List<ModelFeignVO> modelFeignVOS = JSONObject.parseArray(apiResp.getData().get("data").toString(),ModelFeignVO.class);
List<MenuNodeVO> nodeList = new ArrayList<>(); List<MenuNodeVO> nodeList = new ArrayList<>();
modelFeignVOS.stream().forEach(item->{ modelFeignVOS.stream().forEach(item->{
MenuNodeVO nodeVO = new MenuNodeVO(item.getModelName(),item.getId(),nodeId); MenuNodeVO nodeVO = new MenuNodeVO(item.getModelName(),item.getId(),nodeId,2);
nodeList.add(nodeVO); nodeList.add(nodeVO);
}); });
return nodeList; return nodeList;
...@@ -320,7 +320,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity ...@@ -320,7 +320,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
List<ModelCensusFeignVO> modelCensusFeignVOS = JSONObject.parseArray(apiResp.getData().get("data").toString(),ModelCensusFeignVO.class); List<ModelCensusFeignVO> modelCensusFeignVOS = JSONObject.parseArray(apiResp.getData().get("data").toString(),ModelCensusFeignVO.class);
List<MenuNodeVO> nodeList = new ArrayList<>(); List<MenuNodeVO> nodeList = new ArrayList<>();
modelCensusFeignVOS.stream().forEach(item->{ modelCensusFeignVOS.stream().forEach(item->{
MenuNodeVO nodeVO = new MenuNodeVO(item.getCensusName(),item.getId(),nodeId); MenuNodeVO nodeVO = new MenuNodeVO(item.getCensusName(),item.getId(),nodeId,1);
nodeList.add(nodeVO); nodeList.add(nodeVO);
}); });
return nodeList; return nodeList;
......
...@@ -10,11 +10,12 @@ import com.mortals.xhx.module.menu.model.MenuEntity; ...@@ -10,11 +10,12 @@ import com.mortals.xhx.module.menu.model.MenuEntity;
import com.mortals.xhx.module.menu.model.vo.MenuNodeVO; import com.mortals.xhx.module.menu.model.vo.MenuNodeVO;
import com.mortals.xhx.module.menu.service.MenuService; import com.mortals.xhx.module.menu.service.MenuService;
import com.mortals.xhx.module.param.service.ParamService; import com.mortals.xhx.module.param.service.ParamService;
import com.mortals.xhx.module.role.model.RoleAuthEntity;
import com.mortals.xhx.module.role.model.RoleAuthQuery;
import com.mortals.xhx.module.role.service.RoleAuthService;
import com.mortals.xhx.module.role.service.RoleModelService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -33,6 +34,10 @@ public class MenuController extends BaseCRUDJsonBodyMappingController<MenuServic ...@@ -33,6 +34,10 @@ public class MenuController extends BaseCRUDJsonBodyMappingController<MenuServic
@Autowired @Autowired
private ParamService paramService; private ParamService paramService;
@Autowired
private RoleAuthService roleAuthService;
@Autowired
private RoleModelService roleModelService;
public MenuController() { public MenuController() {
super.setModuleDesc("菜单信息业务"); super.setModuleDesc("菜单信息业务");
...@@ -134,12 +139,23 @@ public class MenuController extends BaseCRUDJsonBodyMappingController<MenuServic ...@@ -134,12 +139,23 @@ public class MenuController extends BaseCRUDJsonBodyMappingController<MenuServic
* 查询所有可用菜单(树) * 查询所有可用菜单(树)
*/ */
@PostMapping(value = "list/tree") @PostMapping(value = "list/tree")
public String getMenuList() { public String getMenuList(@RequestBody RoleAuthEntity roleAuthEntity) {
JSONObject ret = new JSONObject(); JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS); ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
try { try {
if(roleAuthEntity.getRoleId()==null){
throw new AppException("角色Id不能为空");
}
List<MenuNodeVO> menuEntityList = this.service.getMenuList(); List<MenuNodeVO> menuEntityList = this.service.getMenuList();
ret.put(KEY_RESULT_DATA,menuEntityList); Map<String,Object> data = new HashMap<>();
data.put("menu",menuEntityList);
Map<String,List<Long>> models = roleModelService.getRoleModelByRole(roleAuthEntity.getRoleId());
data.put("zdbp",models.get("modelIds"));
data.put("sjgl",models.get("censusIds"));
Map<Long,List<Long>> menus = roleAuthService.getMenuIdByRole(roleAuthEntity.getRoleId());
data.put("sjjs",menus.get(3l));
data.put("ptsz",menus.get(4l));
ret.put(KEY_RESULT_DATA,data);
} catch (Exception e) { } catch (Exception e) {
log.error("更新错误", e); log.error("更新错误", e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE); ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
......
...@@ -4,6 +4,9 @@ import com.mortals.framework.service.ICRUDService; ...@@ -4,6 +4,9 @@ import com.mortals.framework.service.ICRUDService;
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 java.util.List;
import java.util.Map;
/** /**
* RoleAuthService * RoleAuthService
* <p> * <p>
...@@ -18,4 +21,11 @@ public interface RoleAuthService extends ICRUDService<RoleAuthEntity, Long> { ...@@ -18,4 +21,11 @@ public interface RoleAuthService extends ICRUDService<RoleAuthEntity, Long> {
* 角色分配菜单资源 * 角色分配菜单资源
*/ */
void assignMenu(RoleAuthQuery query); void assignMenu(RoleAuthQuery query);
/**
* 用户拥有的模块
* @param userId
* @return
*/
Map<Long,List<Long>> getMenuIdByRole(Long userId);
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ package com.mortals.xhx.module.role.service; ...@@ -2,6 +2,7 @@ package com.mortals.xhx.module.role.service;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.role.model.RoleModelEntity; import com.mortals.xhx.module.role.model.RoleModelEntity;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -26,4 +27,15 @@ public interface RoleModelService extends ICRUDService<RoleModelEntity,Long>{ ...@@ -26,4 +27,15 @@ public interface RoleModelService extends ICRUDService<RoleModelEntity,Long>{
* @return * @return
*/ */
Map<Long,Long> getModelCensusByUserId(Long userId); Map<Long,Long> getModelCensusByUserId(Long userId);
/**
* 获取角色拥有的模块权限
* @param roleId
* @return
*/
Map<String, List<Long>> getRoleModelByRole(Long roleId);
int deleteByRoleId(Long roleId);
} }
\ No newline at end of file
...@@ -7,11 +7,11 @@ import com.mortals.xhx.module.menu.model.MenuEntity; ...@@ -7,11 +7,11 @@ import com.mortals.xhx.module.menu.model.MenuEntity;
import com.mortals.xhx.module.menu.model.MenuQuery; import com.mortals.xhx.module.menu.model.MenuQuery;
import com.mortals.xhx.module.menu.service.MenuService; 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.*;
import com.mortals.xhx.module.role.model.RoleAuthQuery;
import com.mortals.xhx.module.role.model.RoleModelEntity;
import com.mortals.xhx.module.role.service.RoleAuthService; import com.mortals.xhx.module.role.service.RoleAuthService;
import com.mortals.xhx.module.role.service.RoleModelService; import com.mortals.xhx.module.role.service.RoleModelService;
import com.mortals.xhx.module.role.service.RoleUserService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -26,6 +26,8 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -26,6 +26,8 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
private MenuService menuService; private MenuService menuService;
@Autowired @Autowired
private RoleModelService roleModelService; private RoleModelService roleModelService;
@Autowired
private RoleUserService roleUserService;
@Override @Override
public void assignMenu(RoleAuthQuery query) { public void assignMenu(RoleAuthQuery query) {
...@@ -48,9 +50,9 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -48,9 +50,9 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
}).collect(Collectors.toList()); }).collect(Collectors.toList());
this.save(list); this.save(list);
roleModelService.deleteByRoleId(roleId);
RoleModelEntity update = new RoleModelEntity(); RoleModelEntity update = new RoleModelEntity();
update.setRoleId(roleId); update.setRoleId(roleId);
roleModelService.remove(update,null);
update.setModelIds(query.getModelIds()); update.setModelIds(query.getModelIds());
update.setCensusIds(query.getCensusIds()); update.setCensusIds(query.getCensusIds());
roleModelService.save(update); roleModelService.save(update);
...@@ -67,4 +69,31 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro ...@@ -67,4 +69,31 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
} }
} }
@Override
public Map<Long,List<Long>> getMenuIdByRole(Long roleId) {
RoleAuthQuery condition = new RoleAuthQuery();
condition.setRoleId(roleId);
List<RoleAuthEntity> roleModelEntities = this.find(condition);
if(CollectionUtils.isNotEmpty(roleModelEntities)) {
List<Long> menuIds = roleModelEntities.stream().map(RoleAuthEntity::getMenuId).collect(Collectors.toList());
MenuQuery query1 = new MenuQuery();
query1.setIdList(menuIds);
List<MenuEntity> menuEntities = menuService.find(query1);
Map<Long,List<Long>> map = new HashMap<>();
menuEntities.forEach(m->{
if(map.containsKey(m.getParentId())){
map.get(m.getParentId()).add(m.getId());
}else {
List<Long> menuIdList = new ArrayList<>();
menuIdList.add(m.getId());
map.put(m.getParentId(),menuIdList);
}
});
return map;
}else {
return Collections.emptyMap();
}
}
} }
\ No newline at end of file
...@@ -6,6 +6,7 @@ import com.mortals.xhx.module.role.model.RoleUserEntity; ...@@ -6,6 +6,7 @@ import com.mortals.xhx.module.role.model.RoleUserEntity;
import com.mortals.xhx.module.role.service.RoleUserService; import com.mortals.xhx.module.role.service.RoleUserService;
import com.mortals.xhx.module.user.model.UserEntity; import com.mortals.xhx.module.user.model.UserEntity;
import com.mortals.xhx.module.user.service.UserService; import com.mortals.xhx.module.user.service.UserService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
...@@ -57,6 +58,26 @@ public class RoleModelServiceImpl extends AbstractCRUDServiceImpl<RoleModelDao, ...@@ -57,6 +58,26 @@ public class RoleModelServiceImpl extends AbstractCRUDServiceImpl<RoleModelDao,
return map; return map;
} }
@Override
public Map<String, List<Long>> getRoleModelByRole(Long roleId) {
RoleModelQuery condition = new RoleModelQuery();
condition.setRoleId(roleId);
List<RoleModelEntity> roleModelEntities = this.find(condition);
Map<String, List<Long>> map = new HashMap<>();
if(CollectionUtils.isNotEmpty(roleModelEntities)){
List<String> censusIds = StringUtils.converStr2List(roleModelEntities.get(0).getCensusIds());
List<Long> ids = censusIds.stream().map(s -> DataUtil.converStr2Long(s.trim(),0)).collect(Collectors.toList());
List<String> modelIds = StringUtils.converStr2List(roleModelEntities.get(0).getModelIds());
List<Long> idsm = modelIds.stream().map(s -> DataUtil.converStr2Long(s.trim(),0)).collect(Collectors.toList());
map.put("censusIds",ids);
map.put("modelIds",idsm);
}else {
map.put("censusIds",Collections.emptyList());
map.put("modelIds",Collections.emptyList());
}
return map;
}
private List<RoleModelEntity> getListByUser(Long userId){ private List<RoleModelEntity> getListByUser(Long userId){
RoleUserEntity query = new RoleUserEntity(); RoleUserEntity query = new RoleUserEntity();
query.setUserId(userId); query.setUserId(userId);
...@@ -70,4 +91,11 @@ public class RoleModelServiceImpl extends AbstractCRUDServiceImpl<RoleModelDao, ...@@ -70,4 +91,11 @@ public class RoleModelServiceImpl extends AbstractCRUDServiceImpl<RoleModelDao,
List<RoleModelEntity> roleModelEntities = this.find(condition); List<RoleModelEntity> roleModelEntities = this.find(condition);
return roleModelEntities; return roleModelEntities;
} }
@Override
public int deleteByRoleId(Long roleId) {
Map<String, Object> condition = new HashMap<>();
condition.put("roleId", roleId);
return this.dao.delete(condition);
}
} }
\ No newline at end of file
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