From a9185be6dbd5fa663ab8ce69ad6b7ff6ddf16296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Fri, 2 Nov 2018 20:45:51 +0800 Subject: [PATCH] =?UTF-8?q?:recycle:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E3=80=82=20lambda=20=E8=A1=A8=E8=BE=BE=E5=BC=8F?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pig4cloud/pigx/admin/api/vo/TreeUtil.java | 8 +-- .../pigx/admin/controller/DictController.java | 30 ++++----- .../pigx/admin/controller/MenuController.java | 51 ++++++++------- .../admin/service/SysDeptRelationService.java | 21 +++++++ .../impl/SysDeptRelationServiceImpl.java | 53 ++++++++++++++++ .../service/impl/SysDeptServiceImpl.java | 62 ++++++------------- .../admin/service/impl/SysLogServiceImpl.java | 28 ++++----- .../service/impl/SysRoleMenuServiceImpl.java | 24 +++---- .../service/impl/SysUserServiceImpl.java | 48 ++++++-------- .../pigx/codegen/PigxCodeGenApplication.java | 2 + 10 files changed, 185 insertions(+), 142 deletions(-) diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/TreeUtil.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/TreeUtil.java index a695f5c27..c048e79a5 100644 --- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/TreeUtil.java +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/TreeUtil.java @@ -40,7 +40,7 @@ public class TreeUtil { */ public static List bulid(List treeNodes, Object root) { - List trees = new ArrayList(); + List trees = new ArrayList<>(); for (T treeNode : treeNodes) { @@ -51,7 +51,7 @@ public class TreeUtil { for (T it : treeNodes) { if (it.getParentId() == treeNode.getId()) { if (treeNode.getChildren() == null) { - treeNode.setChildren(new ArrayList()); + treeNode.setChildren(new ArrayList<>()); } treeNode.add(it); } @@ -86,7 +86,7 @@ public class TreeUtil { for (T it : treeNodes) { if (treeNode.getId() == it.getParentId()) { if (treeNode.getChildren() == null) { - treeNode.setChildren(new ArrayList()); + treeNode.setChildren(new ArrayList<>()); } treeNode.add(findChildren(it, treeNodes)); } @@ -102,7 +102,7 @@ public class TreeUtil { * @return */ public static List bulidTree(List menus, int root) { - List trees = new ArrayList(); + List trees = new ArrayList<>(); MenuTree node; for (SysMenu menu : menus) { node = new MenuTree(); diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java index bc930fb1e..2bdeed422 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java @@ -47,7 +47,7 @@ import java.util.Map; * @since 2017-11-19 */ @RestController -@RequestMapping("/dict") +@RequestMapping("/dict" ) public class DictController { @Autowired private SysDictService sysDictService; @@ -58,7 +58,7 @@ public class DictController { * @param id ID * @return 字典信息 */ - @GetMapping("/{id}") + @GetMapping("/{id}" ) public SysDict dict(@PathVariable Integer id) { return sysDictService.selectById(id); } @@ -69,7 +69,7 @@ public class DictController { * @param params 分页对象 * @return 分页对象 */ - @GetMapping("/dictPage") + @GetMapping("/dictPage" ) public Page dictPage(@RequestParam Map params) { return sysDictService.selectPage(new Query<>(params), new EntityWrapper<>()); } @@ -80,8 +80,8 @@ public class DictController { * @param type 类型 * @return 同类型字典 */ - @GetMapping("/type/{type}") - @Cacheable(value = "dict_details", key = "#type") + @GetMapping("/type/{type}" ) + @Cacheable(value = "dict_details", key = "#type" ) public List findDictByType(@PathVariable String type) { SysDict condition = new SysDict(); condition.setDelFlag(CommonConstant.STATUS_NORMAL); @@ -95,10 +95,10 @@ public class DictController { * @param sysDict 字典信息 * @return success、false */ - @SysLog("添加字典") + @SysLog("添加字典" ) @PostMapping - @CacheEvict(value = "dict_details", key = "#sysDict.type") - @PreAuthorize("@pms.hasPermission('sys_dict_add')") + @CacheEvict(value = "dict_details", key = "#sysDict.type" ) + @PreAuthorize("@pms.hasPermission('sys_dict_add')" ) public R dict(@Valid @RequestBody SysDict sysDict) { return new R<>(sysDictService.insert(sysDict)); } @@ -110,10 +110,10 @@ public class DictController { * @param type 类型 * @return R */ - @SysLog("删除字典") - @DeleteMapping("/{id}/{type}") - @CacheEvict(value = "dict_details", key = "#type") - @PreAuthorize("@pms.hasPermission('sys_dict_del')") + @SysLog("删除字典" ) + @DeleteMapping("/{id}/{type}" ) + @CacheEvict(value = "dict_details", key = "#type" ) + @PreAuthorize("@pms.hasPermission('sys_dict_del')" ) public R deleteDict(@PathVariable Integer id, @PathVariable String type) { return new R<>(sysDictService.deleteById(id)); } @@ -125,9 +125,9 @@ public class DictController { * @return success/false */ @PutMapping - @SysLog("修改字典") - @CacheEvict(value = "dict_details", key = "#sysDict.type") - @PreAuthorize("@pms.hasPermission('sys_dict_edit')") + @SysLog("修改字典" ) + @CacheEvict(value = "dict_details", key = "#sysDict.type" ) + @PreAuthorize("@pms.hasPermission('sys_dict_edit')" ) public R editDict(@Valid @RequestBody SysDict sysDict) { return new R<>(sysDictService.updateById(sysDict)); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/MenuController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/MenuController.java index b6b5b499d..98619e531 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/MenuController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/MenuController.java @@ -19,7 +19,6 @@ package com.pig4cloud.pigx.admin.controller; -import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.pig4cloud.pigx.admin.api.dto.MenuTree; import com.pig4cloud.pigx.admin.api.entity.SysMenu; @@ -34,14 +33,18 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; -import java.util.*; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * @author lengleng * @date 2017/10/31 */ @RestController -@RequestMapping("/menu") +@RequestMapping("/menu" ) public class MenuController { @Autowired private SysMenuService sysMenuService; @@ -52,7 +55,7 @@ public class MenuController { * @param role 角色名称 * @return 菜单列表 */ - @GetMapping("/findMenuByRole/{role}") + @GetMapping("/findMenuByRole/{role}" ) public List findMenuByRole(@PathVariable String role) { return sysMenuService.findMenuByRoleCode(role); } @@ -62,18 +65,17 @@ public class MenuController { * * @return 当前用户的树形菜单 */ - @GetMapping(value = "/userMenu") + @GetMapping(value = "/userMenu" ) public List userMenu() { // 获取符合条件得菜单 Set all = new HashSet<>(); - SecurityUtils.getRoles().forEach(roleName -> all.addAll(sysMenuService.findMenuByRoleCode(roleName))); - List menuTreeList = new ArrayList<>(); - all.forEach(menuVo -> { - if (CommonConstant.MENU.equals(menuVo.getType())) { - menuTreeList.add(new MenuTree(menuVo)); - } - }); - CollUtil.sort(menuTreeList, Comparator.comparingInt(MenuTree::getSort)); + SecurityUtils.getRoles().forEach(roleCode -> all.addAll(sysMenuService.findMenuByRoleCode(roleCode))); + + List menuTreeList = all.stream().filter(vo -> CommonConstant.MENU + .equals(vo.getType())) + .map(MenuTree::new) + .sorted(Comparator.comparingInt(MenuTree::getSort)) + .collect(Collectors.toList()); return TreeUtil.bulid(menuTreeList, -1); } @@ -82,7 +84,7 @@ public class MenuController { * * @return 树形菜单 */ - @GetMapping(value = "/allTree") + @GetMapping(value = "/allTree" ) public List getTree() { SysMenu condition = new SysMenu(); condition.setDelFlag(CommonConstant.STATUS_NORMAL); @@ -95,14 +97,11 @@ public class MenuController { * @param roleName 角色名称 * @return 属性集合 */ - @GetMapping("/roleTree/{roleName}") + @GetMapping("/roleTree/{roleName}" ) public List roleTree(@PathVariable String roleName) { - List menus = sysMenuService.findMenuByRoleCode(roleName); - List menuList = new ArrayList<>(); - for (MenuVO menuVo : menus) { - menuList.add(menuVo.getMenuId()); - } - return menuList; + return sysMenuService.findMenuByRoleCode(roleName) + .stream().map(MenuVO::getMenuId) + .collect(Collectors.toList()); } /** @@ -111,7 +110,7 @@ public class MenuController { * @param id 菜单ID * @return 菜单详细信息 */ - @GetMapping("/{id}") + @GetMapping("/{id}" ) public SysMenu menu(@PathVariable Integer id) { return sysMenuService.selectById(id); } @@ -123,7 +122,7 @@ public class MenuController { * @return success/false */ @PostMapping - @PreAuthorize("@pms.hasPermission('sys_menu_add')") + @PreAuthorize("@pms.hasPermission('sys_menu_add')" ) public R menu(@Valid @RequestBody SysMenu sysMenu) { return new R<>(sysMenuService.insert(sysMenu)); } @@ -135,14 +134,14 @@ public class MenuController { * @return success/false * TODO 级联删除下级节点 */ - @DeleteMapping("/{id}") - @PreAuthorize("@pms.hasPermission('sys_menu_del')") + @DeleteMapping("/{id}" ) + @PreAuthorize("@pms.hasPermission('sys_menu_del')" ) public R menuDel(@PathVariable Integer id) { return new R<>(sysMenuService.deleteMenu(id)); } @PutMapping - @PreAuthorize("@pms.hasPermission('sys_menu_edit')") + @PreAuthorize("@pms.hasPermission('sys_menu_edit')" ) public R menuUpdate(@Valid @RequestBody SysMenu sysMenu) { return new R<>(sysMenuService.updateMenuById(sysMenu)); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDeptRelationService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDeptRelationService.java index 4c839b76b..8a69b5659 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDeptRelationService.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysDeptRelationService.java @@ -20,6 +20,7 @@ package com.pig4cloud.pigx.admin.service; import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysDept; import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation; /** @@ -32,4 +33,24 @@ import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation; */ public interface SysDeptRelationService extends IService { + /** + * 新建部门关系 + * + * @param sysDept 部门 + */ + void insertDeptRelation(SysDept sysDept); + + /** + * 通过ID删除部门关系 + * + * @param id + */ + void deleteAllDeptRealtion(Integer id); + + /** + * 更新部门关系 + * + * @param relation + */ + void updateDeptRealtion(SysDeptRelation relation); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java index 0390c698e..a830fea30 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptRelationServiceImpl.java @@ -19,12 +19,18 @@ package com.pig4cloud.pigx.admin.service.impl; +import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysDept; import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation; import com.pig4cloud.pigx.admin.mapper.SysDeptRelationMapper; import com.pig4cloud.pigx.admin.service.SysDeptRelationService; +import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.stream.Collectors; + /** *

* 服务实现类 @@ -34,6 +40,53 @@ import org.springframework.stereotype.Service; * @since 2018-02-12 */ @Service +@AllArgsConstructor public class SysDeptRelationServiceImpl extends ServiceImpl implements SysDeptRelationService { + private final SysDeptRelationMapper sysDeptRelationMapper; + + /** + * 维护部门关系 + * + * @param sysDept 部门 + */ + @Override + public void insertDeptRelation(SysDept sysDept) { + //增加部门关系表 + SysDeptRelation condition = new SysDeptRelation(); + condition.setDescendant(sysDept.getParentId()); + List relationList = sysDeptRelationMapper + .selectList(new EntityWrapper<>(condition)) + .stream().map(relation -> { + relation.setDescendant(sysDept.getDeptId()); + return relation; + }).collect(Collectors.toList()); + this.insertBatch(relationList); + + //自己也要维护到关系表中 + SysDeptRelation own = new SysDeptRelation(); + own.setDescendant(sysDept.getDeptId()); + own.setAncestor(sysDept.getDeptId()); + sysDeptRelationMapper.insert(own); + } + + /** + * 通过ID删除部门关系 + * + * @param id + */ + @Override + public void deleteAllDeptRealtion(Integer id) { + baseMapper.deleteAllDeptRealtion(id); + } + + /** + * 更新部门关系 + * + * @param relation + */ + @Override + public void updateDeptRealtion(SysDeptRelation relation) { + baseMapper.updateDeptRealtion(relation); + } } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java index 7f6ba9e81..61a5c65eb 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysDeptServiceImpl.java @@ -26,7 +26,7 @@ import com.pig4cloud.pigx.admin.api.entity.SysDept; import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation; import com.pig4cloud.pigx.admin.api.vo.TreeUtil; import com.pig4cloud.pigx.admin.mapper.SysDeptMapper; -import com.pig4cloud.pigx.admin.mapper.SysDeptRelationMapper; +import com.pig4cloud.pigx.admin.service.SysDeptRelationService; import com.pig4cloud.pigx.admin.service.SysDeptService; import com.pig4cloud.pigx.common.core.constant.CommonConstant; import lombok.AllArgsConstructor; @@ -34,8 +34,8 @@ import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** *

@@ -48,8 +48,7 @@ import java.util.List; @Service @AllArgsConstructor public class SysDeptServiceImpl extends ServiceImpl implements SysDeptService { - private final SysDeptMapper sysDeptMapper; - private final SysDeptRelationMapper sysDeptRelationMapper; + private final SysDeptRelationService sysDeptRelationService; /** * 添加信息部门 @@ -62,30 +61,10 @@ public class SysDeptServiceImpl extends ServiceImpl impl SysDept sysDept = new SysDept(); BeanUtils.copyProperties(dept, sysDept); this.insert(sysDept); - this.insertDeptRelation(sysDept); + sysDeptRelationService.insertDeptRelation(sysDept); return Boolean.TRUE; } - /** - * 维护部门关系 - * - * @param sysDept 部门 - */ - private void insertDeptRelation(SysDept sysDept) { - //增加部门关系表 - SysDeptRelation deptRelation = new SysDeptRelation(); - deptRelation.setDescendant(sysDept.getParentId()); - List deptRelationList = sysDeptRelationMapper.selectList(new EntityWrapper<>(deptRelation)); - for (SysDeptRelation sysDeptRelation : deptRelationList) { - sysDeptRelation.setDescendant(sysDept.getDeptId()); - sysDeptRelationMapper.insert(sysDeptRelation); - } - //自己也要维护到关系表中 - SysDeptRelation own = new SysDeptRelation(); - own.setDescendant(sysDept.getDeptId()); - own.setAncestor(sysDept.getDeptId()); - sysDeptRelationMapper.insert(own); - } /** * 删除部门 @@ -100,7 +79,7 @@ public class SysDeptServiceImpl extends ServiceImpl impl sysDept.setUpdateTime(LocalDateTime.now()); sysDept.setDelFlag(CommonConstant.STATUS_DEL); this.deleteById(sysDept); - sysDeptRelationMapper.deleteAllDeptRealtion(id); + sysDeptRelationService.deleteAllDeptRealtion(id); return Boolean.TRUE; } @@ -118,7 +97,7 @@ public class SysDeptServiceImpl extends ServiceImpl impl SysDeptRelation relation = new SysDeptRelation(); relation.setAncestor(sysDept.getParentId()); relation.setDescendant(sysDept.getDeptId()); - sysDeptRelationMapper.updateDeptRealtion(relation); + sysDeptRelationService.updateDeptRealtion(relation); return Boolean.TRUE; } @@ -131,7 +110,7 @@ public class SysDeptServiceImpl extends ServiceImpl impl @Override public List selectListTree(EntityWrapper sysDeptEntityWrapper) { sysDeptEntityWrapper.orderBy("order_num", false); - return getDeptTree(this.selectList(sysDeptEntityWrapper), 0); + return getDeptTree(this.selectList(sysDeptEntityWrapper)); } @@ -139,22 +118,19 @@ public class SysDeptServiceImpl extends ServiceImpl impl * 构建部门树 * * @param depts 部门 - * @param root 根节点 * @return */ - private List getDeptTree(List depts, int root) { - List trees = new ArrayList<>(); - DeptTree node; - for (SysDept dept : depts) { - if (dept.getParentId().equals(dept.getDeptId())) { - continue; - } - node = new DeptTree(); - node.setId(dept.getDeptId()); - node.setParentId(dept.getParentId()); - node.setName(dept.getName()); - trees.add(node); - } - return TreeUtil.bulid(trees, root); + private List getDeptTree(List depts) { + + List treeList = depts.stream() + .filter(dept -> !dept.getDeptId().equals(dept.getParentId())) + .map(dept -> { + DeptTree node = new DeptTree(); + node.setId(dept.getDeptId()); + node.setParentId(dept.getParentId()); + node.setName(dept.getName()); + return node; + }).collect(Collectors.toList()); + return TreeUtil.bulid(treeList, 0); } } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java index 6a66d2449..4e8a7ce34 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysLogServiceImpl.java @@ -28,8 +28,8 @@ import com.pig4cloud.pigx.common.core.constant.CommonConstant; import org.springframework.stereotype.Service; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** *

@@ -60,18 +60,18 @@ public class SysLogServiceImpl extends ServiceImpl impleme */ @Override public Boolean insertLogs(List preLogVoList) { - List sysLogs = new ArrayList<>(); - preLogVoList.forEach(pre -> { - SysLog log = new SysLog(); - log.setType(CommonConstant.STATUS_LOCK); - log.setTitle(pre.getInfo()); - log.setException(pre.getStack()); - log.setParams(pre.getMessage()); - log.setCreateTime(LocalDateTime.now()); - log.setRequestUri(pre.getUrl()); - log.setCreateBy(pre.getUser()); - sysLogs.add(log); - }); - return this.insertBatch(sysLogs); + List sysLogList = preLogVoList.stream() + .map(pre -> { + SysLog log = new SysLog(); + log.setType(CommonConstant.STATUS_LOCK); + log.setTitle(pre.getInfo()); + log.setException(pre.getStack()); + log.setParams(pre.getMessage()); + log.setCreateTime(LocalDateTime.now()); + log.setRequestUri(pre.getUrl()); + log.setCreateBy(pre.getUser()); + return log; + }).collect(Collectors.toList()); + return this.insertBatch(sysLogList); } } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleMenuServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleMenuServiceImpl.java index 6161a48ec..196216c9b 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleMenuServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleMenuServiceImpl.java @@ -30,9 +30,10 @@ import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; /** *

@@ -54,7 +55,7 @@ public class SysRoleMenuServiceImpl extends ServiceImpl roleMenuList = new ArrayList<>(); - List menuIdList = Arrays.asList(menuIds.split(",")); - - for (String menuId : menuIdList) { - SysRoleMenu roleMenu = new SysRoleMenu(); - roleMenu.setRoleId(roleId); - roleMenu.setMenuId(Integer.valueOf(menuId)); - roleMenuList.add(roleMenu); - } + String[] menuIdList = menuIds.split("," ); + List roleMenuList = Arrays.stream(menuIdList) + .map(menuId -> { + SysRoleMenu roleMenu = new SysRoleMenu(); + roleMenu.setRoleId(roleId); + roleMenu.setMenuId(Integer.valueOf(menuId)); + return roleMenu; + }).collect(Collectors.toList()); //清空userinfo - cacheManager.getCache("user_details").clear(); + Objects.requireNonNull(cacheManager.getCache("user_details" )).clear(); return this.insertBatch(roleMenuList); } } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java index 5dbfab2c1..9f4d73712 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java @@ -19,7 +19,6 @@ package com.pig4cloud.pigx.admin.service.impl; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.mapper.EntityWrapper; @@ -51,10 +50,8 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; /** * @author lengleng @@ -78,7 +75,7 @@ public class SysUserServiceImpl extends ServiceImpl impl * @return */ @Override - @Cacheable(value = "user_details", key = "#username",unless = "#result == null") + @Cacheable(value = "user_details", key = "#username", unless = "#result == null" ) public UserInfo findUserInfo(String type, String username) { SysUser condition = new SysUser(); if (EnumLoginType.PWD.getType().equals(type)) { @@ -97,25 +94,20 @@ public class SysUserServiceImpl extends ServiceImpl impl userInfo.setSysUser(sysUser); //设置角色列表 List roleList = sysRoleService.findRolesByUserId(sysUser.getUserId()); - List roleCodes = new ArrayList<>(); - if (CollUtil.isNotEmpty(roleList)) { - roleList.forEach(sysRole -> roleCodes.add(sysRole.getRoleCode())); - } - userInfo.setRoles(ArrayUtil.toArray(roleCodes, String.class)); + //设置角色列表 + List roleCodes = roleList.stream().map(SysRole::getRoleCode).collect(Collectors.toList()); + String[] roles = ArrayUtil.toArray(roleCodes, String.class); + userInfo.setRoles(roles); //设置权限列表(menu.permission) - Set menuVoSet = new HashSet<>(); - for (String role : roleCodes) { - List menuVos = sysMenuService.findMenuByRoleCode(role); - menuVoSet.addAll(menuVos); - } Set permissions = new HashSet<>(); - for (MenuVO menuVo : menuVoSet) { - if (StringUtils.isNotEmpty(menuVo.getPermission())) { - String permission = menuVo.getPermission(); - permissions.add(permission); - } - } + Arrays.stream(roles).forEach(role -> { + List menuVos = sysMenuService.findMenuByRoleCode(role); + List permissionList = menuVos.stream() + .filter(menuVo -> StringUtils.isNotEmpty(menuVo.getPermission())) + .map(MenuVO::getPermission).collect(Collectors.toList()); + permissions.addAll(permissionList); + }); userInfo.setPermissions(ArrayUtil.toArray(permissions, String.class)); return userInfo; } @@ -123,10 +115,10 @@ public class SysUserServiceImpl extends ServiceImpl impl @Override public Page selectWithRolePage(Query query) { DataScope dataScope = new DataScope(); - dataScope.setScopeName("deptId"); + dataScope.setScopeName("deptId" ); dataScope.setIsOnly(true); dataScope.setDeptIds(getChildDepts()); - Object username = query.getCondition().get("username"); + Object username = query.getCondition().get("username" ); query.setRecords(sysUserMapper.selectUserVoPage(query, username, dataScope)); return query; } @@ -177,7 +169,7 @@ public class SysUserServiceImpl extends ServiceImpl impl * @return Boolean */ @Override - @CacheEvict(value = "user_details", key = "#sysUser.username") + @CacheEvict(value = "user_details", key = "#sysUser.username" ) public Boolean deleteUserById(SysUser sysUser) { sysUserRoleService.deleteByUserId(sysUser.getUserId()); this.deleteById(sysUser.getUserId()); @@ -185,7 +177,7 @@ public class SysUserServiceImpl extends ServiceImpl impl } @Override - @CacheEvict(value = "user_details", key = "#username") + @CacheEvict(value = "user_details", key = "#username" ) public R updateUserInfo(UserDTO userDto, String username) { UserVO userVO = sysUserMapper.selectUserVoByUsername(username); SysUser sysUser = new SysUser(); @@ -195,7 +187,7 @@ public class SysUserServiceImpl extends ServiceImpl impl sysUser.setPassword(ENCODER.encode(userDto.getNewpassword1())); } else { log.warn("原密码错误,修改密码失败:{}", username); - return new R<>(Boolean.FALSE, "原密码错误,修改失败"); + return new R<>(Boolean.FALSE, "原密码错误,修改失败" ); } } sysUser.setPhone(userDto.getPhone()); @@ -205,7 +197,7 @@ public class SysUserServiceImpl extends ServiceImpl impl } @Override - @CacheEvict(value = "user_details", key = "#username") + @CacheEvict(value = "user_details", key = "#username" ) public Boolean updateUser(UserDTO userDto, String username) { SysUser sysUser = new SysUser(); BeanUtils.copyProperties(userDto, sysUser); diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java index 6a393292e..cde1505d8 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java @@ -17,6 +17,7 @@ package com.pig4cloud.pigx.codegen; +import com.pig4cloud.pigx.common.security.feign.EnablePigxFeignClients; import com.pig4cloud.pigx.common.swagger.annotation.EnablePigxSwagger2; import org.springframework.boot.SpringApplication; import org.springframework.cloud.client.SpringCloudApplication; @@ -28,6 +29,7 @@ import org.springframework.cloud.client.SpringCloudApplication; */ @EnablePigxSwagger2 @SpringCloudApplication +@EnablePigxFeignClients public class PigxCodeGenApplication { public static void main(String[] args) {