Commit 74371ef5 authored by sherlock's avatar sherlock

Merge branch 'dev_oracle_sherlock' into 'dev_oracle'

admin permission

See merge request root/atms!220
parents 0b9c0dc9 308b970b
...@@ -17,7 +17,6 @@ import pwc.taxtech.atms.thirdparty.ExcelUtil; ...@@ -17,7 +17,6 @@ import pwc.taxtech.atms.thirdparty.ExcelUtil;
import pwc.taxtech.atms.vat.dpo.InputInvoicePreviewQueryParam; import pwc.taxtech.atms.vat.dpo.InputInvoicePreviewQueryParam;
import pwc.taxtech.atms.vat.entity.InputInvoice; import pwc.taxtech.atms.vat.entity.InputInvoice;
import pwc.taxtech.atms.vat.entity.InputInvoiceDetail; import pwc.taxtech.atms.vat.entity.InputInvoiceDetail;
import pwc.taxtech.atms.vat.entity.InputVatInvoiceItem;
import pwc.taxtech.atms.vat.service.impl.InputInvoiceDataImportServiceImpl; import pwc.taxtech.atms.vat.service.impl.InputInvoiceDataImportServiceImpl;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaHelper; import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaHelper;
......
...@@ -31,9 +31,9 @@ public class MenuController { ...@@ -31,9 +31,9 @@ public class MenuController {
@ApiOperation(value = "获取用于显示的菜单列表", notes = "请提供条件参数serviceId") @ApiOperation(value = "获取用于显示的菜单列表", notes = "请提供条件参数serviceId")
@RequestMapping(value = "/display", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @RequestMapping(value = "/display", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody public @ResponseBody
List<MenuDisplayDto> getMenusForDisplay(@RequestParam("serviceId") Integer serviceId) { List<MenuDisplayDto> getMenusForDisplay(@RequestParam("serviceId") Integer serviceId , @RequestParam("userId") String userId) {
logger.info("come into menu display"); logger.info("come into menu display");
return menuService.getMenusForDisplay(serviceId); return menuService.getMenusForDisplay(serviceId, userId);
} }
@ApiOperation(value = "获取菜单列表", notes = "请提供条件参数serviceId") @ApiOperation(value = "获取菜单列表", notes = "请提供条件参数serviceId")
...@@ -44,6 +44,15 @@ public class MenuController { ...@@ -44,6 +44,15 @@ public class MenuController {
return menuService.getMenus(serviceId); return menuService.getMenus(serviceId);
} }
@ApiOperation(value = "获取菜单列表", notes = "请提供条件参数serviceId")
@RequestMapping(value="/role", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
List<MenuDto> getMenus(@RequestParam("serviceId") Integer serviceId, @RequestParam("userId") String userId) {
logger.info("come into menu");
return menuService.getFilterMenus(serviceId, userId);
}
@ResponseBody @ResponseBody
@ApiOperation(value = "更新菜单项", notes = "更新菜单项") @ApiOperation(value = "更新菜单项", notes = "更新菜单项")
@RequestMapping(method = RequestMethod.PUT) @RequestMapping(method = RequestMethod.PUT)
......
...@@ -4,17 +4,22 @@ import org.slf4j.Logger; ...@@ -4,17 +4,22 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
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.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import pwc.taxtech.atms.common.CommonConstants; import pwc.taxtech.atms.common.CommonConstants;
import pwc.taxtech.atms.common.CommonUtils; import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.dao.MenuMapper; import pwc.taxtech.atms.dao.MenuMapper;
import pwc.taxtech.atms.dao.PermissionMapper;
import pwc.taxtech.atms.dao.RolePermissionMapper;
import pwc.taxtech.atms.dao.UserRoleMapper;
import pwc.taxtech.atms.dto.MenuDisplayDto; import pwc.taxtech.atms.dto.MenuDisplayDto;
import pwc.taxtech.atms.dto.MenuDto; import pwc.taxtech.atms.dto.MenuDto;
import pwc.taxtech.atms.entity.Menu; import pwc.taxtech.atms.dto.navtree.DevTreeDto;
import pwc.taxtech.atms.entity.MenuExample; import pwc.taxtech.atms.entity.*;
import pwc.taxtech.atms.exception.ApplicationException; import pwc.taxtech.atms.exception.ApplicationException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -28,19 +33,29 @@ public class MenuServiceImpl { ...@@ -28,19 +33,29 @@ public class MenuServiceImpl {
@Autowired @Autowired
private MenuMapper menuMapper; private MenuMapper menuMapper;
public List<MenuDisplayDto> getMenusForDisplay(Integer moduleId) { @Autowired
private UserRoleMapper userRoleMapper;
@Autowired
private RolePermissionMapper rolePermissionMapper;
@Autowired
private PermissionMapper permissionMapper;
public List<MenuDisplayDto> getMenusForDisplay(Integer moduleId, String userId) {
logger.debug("Start to get menus for display"); logger.debug("Start to get menus for display");
if (moduleId == null) { if (moduleId == null) {
throw new ApplicationException("serviceId for getMenusForDisplay can't be null"); throw new ApplicationException("serviceId for getMenusForDisplay can't be null");
} }
List<MenuDisplayDto> menuDisplayDtos = new ArrayList<>(); List<MenuDisplayDto> menuDisplayDtos = new ArrayList<>();
List<Menu> menus = findByServiceTypeId(moduleId); List<Menu> menus = findByServiceTypeId(moduleId);
List<String> mendIds = getMenuIds(userId);
List<Menu> rootNodes = menus.stream().filter(oneMenu -> !StringUtils.hasText(oneMenu.getParentId())) List<Menu> rootNodes = menus.stream().filter(oneMenu -> !StringUtils.hasText(oneMenu.getParentId()))
.collect(Collectors.toList()); .collect(Collectors.toList());
for (Menu menu : rootNodes) { for (Menu menu : rootNodes) {
// 把EF获取的menu转化为Dto形式 // 把EF获取的menu转化为Dto形式
MenuDisplayDto menuDisplayDto = rotateMenuToMenuDisplayDto(menu); MenuDisplayDto menuDisplayDto = rotateMenuToMenuDisplayDto(menu);
getSubMenuDto(menuDisplayDto, menus); getSubMenuDto(menuDisplayDto, menus, mendIds);
menuDisplayDtos.add(menuDisplayDto); menuDisplayDtos.add(menuDisplayDto);
} }
return menuDisplayDtos; return menuDisplayDtos;
...@@ -62,17 +77,58 @@ public class MenuServiceImpl { ...@@ -62,17 +77,58 @@ public class MenuServiceImpl {
; ;
private void getSubMenuDto(MenuDisplayDto menu, List<Menu> menus) { private void getSubMenuDto(MenuDisplayDto menu, List<Menu> menus, List<String> menuIds) {
List<MenuDisplayDto> subMenuDtos = menus.stream() List<MenuDisplayDto> subMenuDtos = menus.stream()
.filter(oneMenu -> menu.getId().equals(oneMenu.getParentId()) .filter(oneMenu -> menu.getId().equals(oneMenu.getParentId())
&& CommonConstants.ACTIVE_STATUS.equals(oneMenu.getIsActive())) && CommonConstants.ACTIVE_STATUS.equals(oneMenu.getIsActive())
&& menuIds.contains(oneMenu.getId()))
.map(this::rotateMenuToMenuDisplayDto).collect(Collectors.toList()); .map(this::rotateMenuToMenuDisplayDto).collect(Collectors.toList());
menu.setSubMenus(subMenuDtos); menu.setSubMenus(subMenuDtos);
for (MenuDisplayDto subMenu : subMenuDtos) { for (MenuDisplayDto subMenu : subMenuDtos) {
getSubMenuDto(subMenu, menus); getSubMenuDto(subMenu, menus, menuIds);
} }
} }
public List<MenuDto> getFilterMenus(Integer moduleId, String userId){
List<String> menuIds = getMenuIds(userId);
logger.debug("Start to get menus");
if (moduleId == null) {
throw new ApplicationException("serviceId for getMenus can't be null");
}
List<MenuDto> menuDtos = new ArrayList<>();
List<Menu> menus = findByServiceTypeId(moduleId);
for (Menu menu : menus) {
MenuDto menuDto = rotateMenuToMenuDto(menu);
if (!StringUtils.hasText(menu.getParentId())) {
menuDtos.add(menuDto);
}
List<MenuDto> subMenuDtos = menus.stream().filter(oneMenu -> menu.getId().equals(oneMenu.getParentId()))
.map(this::rotateMenuToMenuDto).collect(Collectors.toList());
menuDto.setSubMenus(subMenuDtos);
iteratorMenu2(menus, menuDto, menuIds);
}
return menuDtos;
}
private List<String> getMenuIds(String userId){
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andUserIdEqualTo(userId);
List<String> userRoleIdList = userRoleMapper.selectByExample(userRoleExample).stream().map(UserRole::getRoleId).collect(Collectors.toList());
List<String> permissionIds = rolePermissionMapper.selectByRoleId(userRoleIdList.get(0))
.stream().map(RolePermission::getPermissionId).collect(Collectors.toList());
PermissionExample permissionExample = new PermissionExample();
permissionExample.createCriteria().andIdIn(permissionIds);
List<String> menuIds = permissionMapper.selectByExample(permissionExample)
.stream().map(Permission::getMenuId).collect(Collectors.toList());
// 数据问题,,暂时用这种蠢办法
menuIds.add("91223c21-c15a-4882-89cc-42f3807ec9e3");
menuIds.add("9bf855fb-6b44-49cd-b95b-41a6a9a8c098");
// List<MenuDto> menus = getMenus(moduleId).stream().filter(x -> permissionNames.contains(x.getName())).collect(Collectors.toList());
return menuIds;
}
public List<MenuDto> getMenus(Integer moduleId) { public List<MenuDto> getMenus(Integer moduleId) {
logger.debug("Start to get menus"); logger.debug("Start to get menus");
if (moduleId == null) { if (moduleId == null) {
...@@ -104,7 +160,8 @@ public class MenuServiceImpl { ...@@ -104,7 +160,8 @@ public class MenuServiceImpl {
List<Menu> subMenus = menus.stream().filter(oneMenu -> menu.getId().equals(oneMenu.getParentId())) List<Menu> subMenus = menus.stream().filter(oneMenu -> menu.getId().equals(oneMenu.getParentId()))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (!subMenus.isEmpty()) { if (!subMenus.isEmpty()) {
List<MenuDto> subMenuDtos = subMenus.stream().map(this::rotateMenuToMenuDto).collect(Collectors.toList()); List<MenuDto> subMenuDtos = subMenus.stream()
.map(this::rotateMenuToMenuDto).collect(Collectors.toList());
menu.setSubMenus(subMenuDtos); menu.setSubMenus(subMenuDtos);
for (MenuDto m : subMenuDtos) { for (MenuDto m : subMenuDtos) {
iteratorMenu(menus, m); iteratorMenu(menus, m);
...@@ -112,6 +169,19 @@ public class MenuServiceImpl { ...@@ -112,6 +169,19 @@ public class MenuServiceImpl {
} }
} }
private void iteratorMenu2(List<Menu> menus, MenuDto menu, List<String> menuIds) {
List<Menu> subMenus = menus.stream().filter(oneMenu -> menu.getId().equals(oneMenu.getParentId()))
.collect(Collectors.toList());
if (!subMenus.isEmpty()) {
List<MenuDto> subMenuDtos = subMenus.stream()
.filter(x -> menuIds.contains(x.getId())).map(this::rotateMenuToMenuDto).collect(Collectors.toList());
menu.setSubMenus(subMenuDtos);
for (MenuDto m : subMenuDtos) {
iteratorMenu2(menus, m, menuIds);
}
}
}
public List<Menu> findByIsActive(Boolean isActive) { public List<Menu> findByIsActive(Boolean isActive) {
MenuExample menuExample = new MenuExample(); MenuExample menuExample = new MenuExample();
menuExample.createCriteria().andIsActiveEqualTo(isActive); menuExample.createCriteria().andIsActiveEqualTo(isActive);
......
...@@ -22,7 +22,7 @@ adminHomePageModule ...@@ -22,7 +22,7 @@ adminHomePageModule
} }
$timeout(function () { $timeout(function () {
menuService.getMenusNew(serviceTypeId, function (menuData) { menuService.getAccessMenus(serviceTypeId, loginContext.userId, function (menuData) {
$scope.menuData = menuData; $scope.menuData = menuData;
if ($scope.menuData && $scope.menuData.length > 0) { if ($scope.menuData && $scope.menuData.length > 0) {
......
...@@ -4,8 +4,8 @@ webservices.factory('menuService', ['$http', '$q', 'apiConfig', 'httpCacheServic ...@@ -4,8 +4,8 @@ webservices.factory('menuService', ['$http', '$q', 'apiConfig', 'httpCacheServic
'use strict'; 'use strict';
return { return {
getMenusForDisplay: function (serviceId) { getMenusForDisplay: function (serviceId, userId) {
return httpCacheService.get('/menu/display?serviceId=' + serviceId); return httpCacheService.get('/menu/display?serviceId=' + serviceId + "&userId=" + userId);
//return $http.get('/menu/display?serviceId=' + serviceId, apiConfig.create()); //return $http.get('/menu/display?serviceId=' + serviceId, apiConfig.create());
}, },
getMenus: function (serviceId) { getMenus: function (serviceId) {
...@@ -15,6 +15,9 @@ webservices.factory('menuService', ['$http', '$q', 'apiConfig', 'httpCacheServic ...@@ -15,6 +15,9 @@ webservices.factory('menuService', ['$http', '$q', 'apiConfig', 'httpCacheServic
getMenusNew: function (serviceId, fn) { getMenusNew: function (serviceId, fn) {
return httpCacheService.getCache('/menu?serviceId=' + serviceId, false, fn); return httpCacheService.getCache('/menu?serviceId=' + serviceId, false, fn);
}, },
getAccessMenus: function (serviceId, userId, fn) {
return httpCacheService.getCache('/menu/role?serviceId=' + serviceId + '&userId=' + userId, false, fn);
},
GetMenusForIvhTree: function (serviceId) { GetMenusForIvhTree: function (serviceId) {
return $http.get('/menu/GetMenusForIvhTree?serviceId=' + serviceId, apiConfig.create()); return $http.get('/menu/GetMenusForIvhTree?serviceId=' + serviceId, apiConfig.create());
}, },
......
...@@ -11,7 +11,7 @@ frameworkModule.controller('appSideBarController', ['$scope', '$log', 'menuServi ...@@ -11,7 +11,7 @@ frameworkModule.controller('appSideBarController', ['$scope', '$log', 'menuServi
userService.getUserPermission(loginContext.userName).success(function (data) { userService.getUserPermission(loginContext.userName).success(function (data) {
$timeout(function () { $timeout(function () {
menuService.getMenusForDisplay(1).success(function (menuData) { menuService.getMenusForDisplay(1, loginContext.userId).success(function (menuData) {
$scope.menuData = menuData; $scope.menuData = menuData;
}); });
}, 500); }, 500);
......
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