用户列表部分分配

This commit is contained in:
zhangzhiqiang
2022-12-26 15:17:21 +08:00
parent ce48bec077
commit 63edd961b9
13 changed files with 87 additions and 40 deletions

View File

@@ -2,6 +2,7 @@ package org.nl.common.enums;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.domain.query.LConsumer;
import java.util.Collection;
@@ -20,7 +21,7 @@ public enum QueryTEnum {
BY((q, k, v) -> { q.orderByDesc(k[0],v); }),
NO((q, k, v) -> { q.isNull(k[0]); }),
LT((q, k, v) -> { q.lt(k[0],v); }),
OREQ((q, k, v) -> { if (v == null){ q.isNull(k[0]); }else { q.eq(k[0],v); } });
OREQ((q, k, v) -> { if (StringUtils.isBlank((String)v)){ q.isNull(k[0]); }else { q.eq(k[0],v); } });
private LConsumer<QueryWrapper,String[], Object> doP;

View File

@@ -75,7 +75,7 @@ public class SysMenuController {
@GetMapping
@ApiOperation("查询菜单")
@SaCheckPermission("menu:list")
public ResponseEntity<Object> pageQuery(@RequestParam Map query, PageQuery page) throws Exception {
public ResponseEntity<Object> pageQuery(MenuQuery query, PageQuery page) throws Exception {
List list = iSysMenuService.query(query, page);
return new ResponseEntity<>(TableDataInfo.build(list), HttpStatus.OK);
}

View File

@@ -34,7 +34,7 @@ public interface ISysMenuService extends IService<SysMenu> {
* @param page
* @return
*/
List query(Map query, PageQuery page);
List query(MenuQuery query, PageQuery page);
/**
* 根据ID获取同级与上级数据

View File

@@ -1,12 +1,11 @@
package org.nl.system.service.menu.dao;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
@@ -32,6 +31,7 @@ public class SysMenu implements Serializable {
/**
* 上级菜单ID
*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String pid;
/**
@@ -117,7 +117,7 @@ public class SysMenu implements Serializable {
/**
* 创建时间
*/
private String createTime;
private Date createTime;
/**
* 修改人标识
@@ -132,7 +132,7 @@ public class SysMenu implements Serializable {
/**
* 修改时间
*/
private String updateTime;
private Date updateTime;
}

View File

@@ -57,4 +57,6 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
void untiedMenu(String menuId);
List<Map> getMenusByRole(@Param("systemType") String systemType, @Param("category")String category);
String findAllChild(String pid);
}

View File

@@ -85,4 +85,17 @@
and category = #{category}
</if>
</select>
<select id="findAllChild" resultType="java.lang.String">
SELECT
max(t3.childId) as menus
from
(
select *,
if( find_in_set(t1.pid, @p) > 0,@p := concat(@p,',',id),0 ) as childId
from
(select menu_id as id, pid from sys_menu t order by id) t1,
(select @p := #{pid}) t2
) t3
where childId != '0'
</select>
</mapper>

View File

@@ -48,6 +48,7 @@ public class MenuDto extends BaseDTO implements Serializable {
private Boolean iframe;
private String systemType;
private Boolean cache;

View File

@@ -14,9 +14,11 @@ import org.nl.system.service.menu.dao.SysMenu;
*/
@Data
public class MenuQuery extends BaseQuery<SysMenu> {
private String pid = " ";
private String pid = "";
private String systemType;
@Override
public void paramMapping() {
this.doP.put("pid", QParam.builder().k(new String[]{"pid"}).type(QueryTEnum.OREQ).build());
this.doP.put("blurry", QParam.builder().k(new String[]{"title"}).type(QueryTEnum.LK).build());
}
}

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
@@ -24,8 +25,10 @@ import org.nl.system.service.menu.dto.MenuDto;
import org.nl.system.service.menu.ISysMenuService;
import org.nl.system.service.menu.dao.SysMenu;
import org.nl.system.service.menu.dao.mapper.SysMenuMapper;
import org.nl.system.service.menu.dto.MenuQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
@@ -55,15 +58,11 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override
public List query(Map query, PageQuery page) {
String pid = MapUtil.getStr(query, "pid");
QueryWrapper<SysMenu> wrapper = new QueryWrapper<>();
if (StringUtils.isEmpty(pid)){
wrapper.isNull("pid");
}else {
wrapper.eq("pid",pid);
public List query(MenuQuery query, PageQuery page) {
if (StringUtils.isNotEmpty(query.getBlurry())){
query.setPid(null);
}
Page<SysMenu> menuPage = this.page(page.build(), wrapper);
Page<SysMenu> menuPage = this.page(page.build(), query.build());
List<MenuDto> collect = menuPage.getRecords().stream().map(menu -> this.doToDto(menu)).collect(Collectors.toList());
return collect;
}
@@ -121,12 +120,13 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
resources.setPid(null);
addSystemTypeDict(resources);
}
updateRootSystemType(resources);
baseMapper.insert(resources);
// 计算子节点数目
resources.setSubCount(0);
// 更新父节点菜单数目
updateSubCnt(resources.getPid());
updateRootSystemType(resources);
}
private void addSystemTypeDict(SysMenu resources) {
@@ -149,14 +149,14 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
}
SysMenu rootMenu = this.findById(rootMenuId);
sysMenu.setSystemType(rootMenu.getSystemType());
this.updateById(sysMenu);
}
private String findRootMenuId(String menuId) {
SysMenu sysMenu = this.findById(menuId);
String pid = sysMenu.getPid();
if (StrUtil.isEmpty(pid)) {
if (StrUtil.isEmpty(sysMenu.getPid())) {
return menuId;
} else {
return findRootMenuId(pid);
return findRootMenuId(sysMenu.getPid());
}
}
@@ -169,35 +169,46 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
baseMapper.untiedMenu(menu.getMenuId());
baseMapper.deleteById(menu.getMenuId());
String pid = menu.getPid();
if (StringUtils.isNotEmpty(pid)){
if (StringUtils.isEmpty(pid)){
pids.add(pid);
}
updateSubCnt(pid);
}
sysDictMapper.delete(new QueryWrapper<Dict>().in("para1", pids).eq("code", DictConstantPool.DICT_SYS_CODE));
if (!CollectionUtils.isEmpty(pids)){
sysDictMapper.delete(new QueryWrapper<Dict>().in("para1", pids).eq("code", DictConstantPool.DICT_SYS_CODE));
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public void update(SysMenu resources) {
if (resources.getMenuId().equals(resources.getPid())) {
throw new BadRequestException("上级不能为自己");
String menuId = resources.getMenuId();
SysMenu menu = baseMapper.selectById(menuId);
List<String> allChildIds = Arrays.asList(baseMapper.findAllChild(menuId).split(","));
if (allChildIds.contains(resources.getPid())){
throw new BadRequestException("上级不能为自己或自己的下级");
}
SysMenu menu = baseMapper.selectById(resources.getMenuId());
if (resources.getIframe()) {
String http = "http://", https = "https://";
if (!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
throw new BadRequestException("外链必须以http://或者https://开头");
}
}
if (resources.getPid().equals("0")) {
resources.setPid(null);
addSystemTypeDict(resources);
if (StringUtils.isNotEmpty(menu.getPid())){
addSystemTypeDict(resources);
}
}else {
resources.setSystemType(this.findById(resources.getPid()).getSystemType());
}
// 记录的父节点ID
String oldPid = menu.getPid();
String newPid = resources.getPid();
// 记录的父节点ID
if (oldPid == null && newPid != null){
sysDictMapper.delete(new QueryWrapper<Dict>().eq("para1",menu.getMenuId()));
}
menu.setTitle(resources.getTitle());
menu.setComponent(resources.getComponent());
menu.setPath(resources.getPath());
@@ -214,6 +225,11 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
// 计算父级菜单节点数目
updateSubCnt(oldPid);
updateSubCnt(newPid);
//更新SystemType
if (!resources.getSystemType().equals(menu.getSystemType())){
this.update(new UpdateWrapper<SysMenu>().set(DictConstantPool.DICT_SYS_CODE,resources.getSystemType()).in("menu_id",allChildIds));
}
}
/**
@@ -338,6 +354,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
menuDto.setMenuSort(entity.getMenuSort());
menuDto.setPath(entity.getPath());
menuDto.setComponent(entity.getComponent());
menuDto.setSystemType(entity.getSystemType());
menuDto.setPid(entity.getPid());
menuDto.setSubCount(entity.getSubCount());
menuDto.setIframe(entity.getIframe());
@@ -345,6 +362,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
menuDto.setHidden(entity.getHidden());
menuDto.setComponentName(entity.getComponentName());
menuDto.setIcon(entity.getIcon());
menuDto.setCreateTime(entity.getCreateTime());
//构建前端需要的数据结构树
Integer sub_count = entity.getSubCount();

View File

@@ -67,7 +67,8 @@
left join sys_dept on sys_user_dept.dept_id = sys_dept.dept_id
<where>
<if test="query.deptId != null">
and sys_dept.dept_id = #{query.deptId}
and
sys_user.user_id in (select user_id from sys_user_dept where dept_id = #{query.deptId})
</if>
<if test="query.isUsed != null">
and sys_user.is_used = #{query.isUsed}

View File

@@ -35,6 +35,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
@@ -106,7 +107,6 @@ public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
}
@Override
@SneakyThrows
@Transactional
public void update(Map userDetail) {
if(CollectionUtils.isEmpty(userDetail)|| userDetail.get("userId")==null){
@@ -127,7 +127,11 @@ public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
}
}
}, Date.class);
BeanUtils.populate(sysUser,userDetail);
try {
BeanUtils.populate(sysUser,userDetail);
}catch (Exception ex){
throw new RuntimeException();
}
sysUser.setUpdateTime(new Date());
sysUser.setUpdateId(SecurityUtils.getCurrentUserId());
this.updateById(sysUser);
@@ -135,9 +139,9 @@ public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
deptService.delUserDeptRelation(sysUser.getUserId());
deptService.saveUserDeptRelation(sysUser.getUserId(), (List) userDetail.get("deptIds"));
};
if (userDetail.get("roleIds") !=null){
if (userDetail.get("rolesIds") !=null){
roleService.delUserRoleRelation(sysUser.getUserId());
roleService.saveUserRoleRelation(sysUser.getUserId(),(List) userDetail.get("roleIds"));
roleService.saveUserRoleRelation(sysUser.getUserId(),(List) userDetail.get("rolesIds"));
}
}
}

View File

@@ -16,7 +16,7 @@
<el-select
v-model="query.systemType"
style="width: 100px; height: 35px;top: -5px;"
placeholder="切换系统"
placeholder="所属系统"
@change="changetype"
>
<el-option
@@ -150,9 +150,9 @@
>
<el-table-column type="selection" width="55" />
<el-table-column label="菜单标题" prop="title" :min-width="100" />
<el-table-column label="系统" prop="systemType" :min-width="flexWidth('systemType',crud.data,'系统')">
<el-table-column label="所属系统" prop="systemType" :min-width="flexWidth('systemType',crud.data,'所属系统')">
<template slot-scope="scope">
{{ dict.label.system_type[scope.row.systemType] }}
{{ dict.label.system_type[scope.row.systemType] }} : {{scope.row.systemType}}
</template>
</el-table-column>
<el-table-column prop="icon" label="图标" align="center" :min-width="flexWidth('icon',crud.data,'图标')">
@@ -185,7 +185,7 @@
<span v-else>是</span>
</template>
</el-table-column>
<el-table-column prop="create_time" label="创建日期" :min-width="flexWidth('create_time',crud.data,'创建日期')" />
<el-table-column prop="createTime" label="创建日期" :min-width="flexWidth('createTime',crud.data,'创建日期')" />
<el-table-column
v-permission="['admin','menu:edit','menu:del']"
label="操作"

View File

@@ -509,7 +509,12 @@ export default {
// 获取左侧部门数据
getDeptDatas(node, resolve) {
setTimeout(() => {
crudDept.getDeptTree({ name: node }).then(res => {
var q = {}
// eslint-disable-next-line eqeqeq
if (node != '') {
q = { name: node }
}
crudDept.getDeptTree(q).then(res => {
console.log('res', res)
if (resolve) {
resolve(res.content)
@@ -584,6 +589,7 @@ export default {
this.query.deptId = data.deptId
this.query.needAll = true
this.crud.toQuery()
this.query.deptId = null
},
// 改变状态
changeEnabled(row) {
@@ -803,7 +809,6 @@ export default {
} else {
user.rolesIds = this.crud.selections.map(item => (item.roleId))
}
debugger
crudUser.edit(user).then(res => {
this.cancelForm()
this.crud.notify('保存成功', CRUD.NOTIFICATION_TYPE.SUCCESS)