mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 12:39:05 +08:00
♻️ 重构代码。 lambda 表达式重构
This commit is contained in:
1 parent
65045e5b4e
commit
a9185be6db
10 files changed
+185
-142
No files matched your search
@@ -40,7 +40,7 @@ public class TreeUtil {
|
||||
*/
|
||||
public static <T extends TreeNode> List<T> bulid(List<T> treeNodes, Object root) {
|
||||
|
||||
List<T> trees = new ArrayList<T>();
|
||||
List<T> 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>());
|
||||
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>());
|
||||
treeNode.setChildren(new ArrayList<>());
|
||||
}
|
||||
treeNode.add(findChildren(it, treeNodes));
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class TreeUtil {
|
||||
* @return
|
||||
*/
|
||||
public static List<MenuTree> bulidTree(List<SysMenu> menus, int root) {
|
||||
List<MenuTree> trees = new ArrayList<MenuTree>();
|
||||
List<MenuTree> trees = new ArrayList<>();
|
||||
MenuTree node;
|
||||
for (SysMenu menu : menus) {
|
||||
node = new MenuTree();
|
||||
|
||||
+15
-15
@@ -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<String, Object> 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<SysDict> 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<Boolean> 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<Boolean> 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<Boolean> editDict(@Valid @RequestBody SysDict sysDict) {
|
||||
return new R<>(sysDictService.updateById(sysDict));
|
||||
}
|
||||
|
||||
+25
-26
@@ -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<MenuVO> findMenuByRole(@PathVariable String role) {
|
||||
return sysMenuService.findMenuByRoleCode(role);
|
||||
}
|
||||
@@ -62,18 +65,17 @@ public class MenuController {
|
||||
*
|
||||
* @return 当前用户的树形菜单
|
||||
*/
|
||||
@GetMapping(value = "/userMenu")
|
||||
@GetMapping(value = "/userMenu" )
|
||||
public List<MenuTree> userMenu() {
|
||||
// 获取符合条件得菜单
|
||||
Set<MenuVO> all = new HashSet<>();
|
||||
SecurityUtils.getRoles().forEach(roleName -> all.addAll(sysMenuService.findMenuByRoleCode(roleName)));
|
||||
List<MenuTree> 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<MenuTree> 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<MenuTree> 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<Integer> roleTree(@PathVariable String roleName) {
|
||||
List<MenuVO> menus = sysMenuService.findMenuByRoleCode(roleName);
|
||||
List<Integer> 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<Boolean> 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<Boolean> 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<Boolean> menuUpdate(@Valid @RequestBody SysMenu sysMenu) {
|
||||
return new R<>(sysMenuService.updateMenuById(sysMenu));
|
||||
}
|
||||
|
||||
+21
@@ -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<SysDeptRelation> {
|
||||
|
||||
/**
|
||||
* 新建部门关系
|
||||
*
|
||||
* @param sysDept 部门
|
||||
*/
|
||||
void insertDeptRelation(SysDept sysDept);
|
||||
|
||||
/**
|
||||
* 通过ID删除部门关系
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void deleteAllDeptRealtion(Integer id);
|
||||
|
||||
/**
|
||||
* 更新部门关系
|
||||
*
|
||||
* @param relation
|
||||
*/
|
||||
void updateDeptRealtion(SysDeptRelation relation);
|
||||
}
|
||||
+53
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
@@ -34,6 +40,53 @@ import org.springframework.stereotype.Service;
|
||||
* @since 2018-02-12
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class SysDeptRelationServiceImpl extends ServiceImpl<SysDeptRelationMapper, SysDeptRelation> implements SysDeptRelationService {
|
||||
private final SysDeptRelationMapper sysDeptRelationMapper;
|
||||
|
||||
/**
|
||||
* 维护部门关系
|
||||
*
|
||||
* @param sysDept 部门
|
||||
*/
|
||||
@Override
|
||||
public void insertDeptRelation(SysDept sysDept) {
|
||||
//增加部门关系表
|
||||
SysDeptRelation condition = new SysDeptRelation();
|
||||
condition.setDescendant(sysDept.getParentId());
|
||||
List<SysDeptRelation> 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);
|
||||
}
|
||||
|
||||
}
|
||||
+19
-43
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -48,8 +48,7 @@ import java.util.List;
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {
|
||||
private final SysDeptMapper sysDeptMapper;
|
||||
private final SysDeptRelationMapper sysDeptRelationMapper;
|
||||
private final SysDeptRelationService sysDeptRelationService;
|
||||
|
||||
/**
|
||||
* 添加信息部门
|
||||
@@ -62,30 +61,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> 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<SysDeptRelation> 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<SysDeptMapper, SysDept> 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<SysDeptMapper, SysDept> 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<SysDeptMapper, SysDept> impl
|
||||
@Override
|
||||
public List<DeptTree> selectListTree(EntityWrapper<SysDept> 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<SysDeptMapper, SysDept> impl
|
||||
* 构建部门树
|
||||
*
|
||||
* @param depts 部门
|
||||
* @param root 根节点
|
||||
* @return
|
||||
*/
|
||||
private List<DeptTree> getDeptTree(List<SysDept> depts, int root) {
|
||||
List<DeptTree> 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<DeptTree> getDeptTree(List<SysDept> depts) {
|
||||
|
||||
List<DeptTree> 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);
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -60,18 +60,18 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertLogs(List<PreLogVo> preLogVoList) {
|
||||
List<SysLog> 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<SysLog> 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);
|
||||
}
|
||||
}
|
||||
+12
-12
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -54,7 +55,7 @@ public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = "menu_details", key = "#role + '_menu'")
|
||||
@CacheEvict(value = "menu_details", key = "#role + '_menu'" )
|
||||
public Boolean insertRoleMenus(String role, Integer roleId, String menuIds) {
|
||||
SysRoleMenu condition = new SysRoleMenu();
|
||||
condition.setRoleId(roleId);
|
||||
@@ -64,18 +65,17 @@ public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRo
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
List<SysRoleMenu> roleMenuList = new ArrayList<>();
|
||||
List<String> 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<SysRoleMenu> 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);
|
||||
}
|
||||
}
|
||||
+20
-28
@@ -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<SysUserMapper, SysUser> 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<SysUserMapper, SysUser> impl
|
||||
userInfo.setSysUser(sysUser);
|
||||
//设置角色列表
|
||||
List<SysRole> roleList = sysRoleService.findRolesByUserId(sysUser.getUserId());
|
||||
List<String> roleCodes = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(roleList)) {
|
||||
roleList.forEach(sysRole -> roleCodes.add(sysRole.getRoleCode()));
|
||||
}
|
||||
userInfo.setRoles(ArrayUtil.toArray(roleCodes, String.class));
|
||||
//设置角色列表
|
||||
List<String> roleCodes = roleList.stream().map(SysRole::getRoleCode).collect(Collectors.toList());
|
||||
String[] roles = ArrayUtil.toArray(roleCodes, String.class);
|
||||
userInfo.setRoles(roles);
|
||||
|
||||
//设置权限列表(menu.permission)
|
||||
Set<MenuVO> menuVoSet = new HashSet<>();
|
||||
for (String role : roleCodes) {
|
||||
List<MenuVO> menuVos = sysMenuService.findMenuByRoleCode(role);
|
||||
menuVoSet.addAll(menuVos);
|
||||
}
|
||||
Set<String> 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<MenuVO> menuVos = sysMenuService.findMenuByRoleCode(role);
|
||||
List<String> 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<SysUserMapper, SysUser> 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<SysUserMapper, SysUser> 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<SysUserMapper, SysUser> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "user_details", key = "#username")
|
||||
@CacheEvict(value = "user_details", key = "#username" )
|
||||
public R<Boolean> updateUserInfo(UserDTO userDto, String username) {
|
||||
UserVO userVO = sysUserMapper.selectUserVoByUsername(username);
|
||||
SysUser sysUser = new SysUser();
|
||||
@@ -195,7 +187,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> 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<SysUserMapper, SysUser> 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);
|
||||
|
||||
+2
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user