修改字典,菜单相关问题
This commit is contained in:
@ -37,7 +37,7 @@ public class DictProjectController{
|
||||
@ApiOperation("插入新数据")
|
||||
@PostMapping("")
|
||||
public BaseResponse<Boolean> insert(@ApiParam(value = "对象数据", required = true) @RequestBody DictProject dictProject){
|
||||
boolean save = dictProjectService.saveOrUpdate(dictProject);
|
||||
boolean save = dictProjectService.insertDictProject(dictProject);
|
||||
return BaseResponse.success(save);
|
||||
}
|
||||
|
||||
@ -80,29 +80,7 @@ public class DictProjectController{
|
||||
@ApiOperation("查询数据集合")
|
||||
@GetMapping("/selectDictList")
|
||||
public BaseResponse<List<DictProject>> selectDictList(DictProject dictProject){
|
||||
List<DictProject> selectDictList = dictProjectService.selectDictList(dictProject);
|
||||
Map<String, DictProject> dictProjectMap = selectDictList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
DictProject::getCode, // 键:dictCode属性
|
||||
project -> project, // 值:DictProject对象本身
|
||||
(existing, replacement) -> existing // 处理键冲突策略:保留现有值
|
||||
));
|
||||
List<DictProject> rootDicts = new ArrayList<>();
|
||||
for (DictProject dict : selectDictList) {
|
||||
String parentCode = dict.getParentCode();
|
||||
|
||||
// 根节点处理
|
||||
if ("/".equals(parentCode)) {
|
||||
rootDicts.add(dict);
|
||||
} else {
|
||||
// 子节点处理
|
||||
DictProject parent = dictProjectMap.get(parentCode);
|
||||
if (parent != null) {
|
||||
parent.getChildren().add(dict);
|
||||
}
|
||||
}
|
||||
}
|
||||
return BaseResponse.success(rootDicts);
|
||||
return BaseResponse.success(dictProjectService.selectDictTree(dictProject));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,14 +20,6 @@ public interface DictProjectMapper extends IBaseMapper<DictProject> {
|
||||
return w;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(dictProject.getDictTypeName())) {
|
||||
w = w.and(i -> i.eq(DictProject::getDictTypeName, dictProject.getDictTypeName()));
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(dictProject.getDictTypeCode())) {
|
||||
w = w.and(i -> i.eq(DictProject::getDictTypeCode, dictProject.getDictTypeCode()));
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,6 @@
|
||||
<result column="dic_name" jdbcType="VARCHAR" property="dicName"/>
|
||||
<result column="parent_code" jdbcType="VARCHAR" property="parentCode"/>
|
||||
<result column="parent_type" jdbcType="VARCHAR" property="parentType"/>
|
||||
<result column="dict_type_code" jdbcType="VARCHAR" property="dictTypeCode"/>
|
||||
<result column="dict_type_name" jdbcType="VARCHAR" property="dictTypeName"/>
|
||||
<result column="use_flag" jdbcType="VARCHAR" property="useFlag"/>
|
||||
<result column="default_flag" jdbcType="VARCHAR" property="defaultFlag"/>
|
||||
<result column="order_flag" jdbcType="INTEGER" property="orderFlag"/>
|
||||
|
@ -46,18 +46,6 @@ public class DictProject implements Serializable {
|
||||
@ApiModelProperty(value = "字典名称")
|
||||
private String dicName;
|
||||
|
||||
/**
|
||||
* 分组编码dictTypeCode
|
||||
*/
|
||||
@ApiModelProperty(value = "分组编码")
|
||||
private String dictTypeCode;
|
||||
|
||||
/**
|
||||
* 分组名称dictTypeName
|
||||
*/
|
||||
@ApiModelProperty(value = "分组名称")
|
||||
private String dictTypeName;
|
||||
|
||||
/**
|
||||
* 父类code
|
||||
*/
|
||||
|
@ -36,6 +36,13 @@ public interface IDictProjectService extends IBaseService<DictProject>{
|
||||
*/
|
||||
List<DictProject> selectDictList(DictProject dictProject);
|
||||
|
||||
/**
|
||||
* 查询所有字典(树形结构)
|
||||
* @param dictProject
|
||||
* @return
|
||||
*/
|
||||
List<DictProject> selectDictTree(DictProject dictProject);
|
||||
|
||||
/**
|
||||
* 查询字典数据
|
||||
* @param parentCode 字典父类code
|
||||
@ -44,4 +51,11 @@ public interface IDictProjectService extends IBaseService<DictProject>{
|
||||
* @return 返回结果
|
||||
*/
|
||||
DictProject getDict(String code, String parentCode, String toParentCode);
|
||||
|
||||
/**
|
||||
* 插入新数据
|
||||
* @param dictProject 字典对象
|
||||
* @return 是否成功
|
||||
*/
|
||||
Boolean insertDictProject(DictProject dictProject);
|
||||
}
|
||||
|
@ -10,36 +10,39 @@ import com.coscoshipping.ebtp.system.dict.service.IDictProjectService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 对数据表 dict_project 操作的 serviceImpl
|
||||
*
|
||||
* @author daixc
|
||||
* @date 2020/11/03
|
||||
*/
|
||||
@Service
|
||||
public class DictProjectServiceImpl extends BaseServiceImpl<DictProjectMapper,DictProject> implements IDictProjectService {
|
||||
public class DictProjectServiceImpl extends BaseServiceImpl<DictProjectMapper, DictProject> implements IDictProjectService {
|
||||
|
||||
|
||||
@Resource DictProjectMapper mapper;
|
||||
@Resource
|
||||
private DictProjectMapper mapper;
|
||||
|
||||
private static final String COMMON_STR = "=";
|
||||
|
||||
private static final String USE_FLAG_YES = "0";
|
||||
|
||||
private static final String DICT_ROOT = "project";
|
||||
|
||||
/**
|
||||
* 字典缓存查询数据
|
||||
*/
|
||||
@Override
|
||||
public Map<String,List<DictProject>> refreshDictCache(){
|
||||
public Map<String, List<DictProject>> refreshDictCache() {
|
||||
QueryWrapper<DictProject> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("use_flag",USE_FLAG_YES);
|
||||
|
||||
queryWrapper.eq("use_flag", USE_FLAG_YES);
|
||||
queryWrapper.orderByAsc("id").orderByAsc("order_flag");
|
||||
|
||||
List<DictProject> dictProjects = this.list(queryWrapper);
|
||||
List<DictProject> dictProjects = this.list(queryWrapper);
|
||||
|
||||
return dictProjects.stream().collect(Collectors.groupingBy(DictProject::getParentType));
|
||||
}
|
||||
@ -47,7 +50,8 @@ public class DictProjectServiceImpl extends BaseServiceImpl<DictProjectMapper,Di
|
||||
|
||||
/**
|
||||
* 查询字典集合
|
||||
* @param parentCode 字典父类code
|
||||
*
|
||||
* @param parentCode 字典父类code
|
||||
* @param toParentCode 字典父类对应的父类code
|
||||
* @return
|
||||
*/
|
||||
@ -60,28 +64,73 @@ public class DictProjectServiceImpl extends BaseServiceImpl<DictProjectMapper,Di
|
||||
queryWrapper.orderByAsc("order_flag");
|
||||
|
||||
return this.list(queryWrapper);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有字典
|
||||
*
|
||||
* @param dictProject
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<DictProject> selectDictList(DictProject dictProject) {
|
||||
return this.list(mapper.getCustomQueryWrapper(dictProject).orderByAsc(DictProject::getOrderFlag).orderByAsc(DictProject::getDictTypeCode));
|
||||
return this.list(mapper.getCustomQueryWrapper(dictProject).orderByAsc(DictProject::getOrderFlag));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DictProject getDict(String code, String parentCode, String toParentCode) {
|
||||
|
||||
DictProject dictProject = null;
|
||||
List<DictProject> dictProjectList = getDictList(parentCode,toParentCode);
|
||||
if(null != dictProjectList && !dictProjectList.isEmpty()){
|
||||
List<DictProject> dictProjectList = getDictList(parentCode, toParentCode);
|
||||
if (null != dictProjectList && !dictProjectList.isEmpty()) {
|
||||
dictProject = dictProjectList.stream().filter(n -> n.getCode().equals(code)).collect(Collectors.toList()).get(0);
|
||||
}
|
||||
return dictProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictProject> selectDictTree(DictProject dictProject) {
|
||||
// 查询所有字典数据(可根据dictProject参数过滤)
|
||||
List<DictProject> allList = this.selectDictList(dictProject);
|
||||
// 构建code->DictProject映射
|
||||
Map<String, DictProject> dictMap = allList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
DictProject::getCode,
|
||||
project -> project,
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
// 组装树结构
|
||||
List<DictProject> rootList = new ArrayList<>();
|
||||
for (DictProject dict : allList) {
|
||||
String parentCode = dict.getParentCode();
|
||||
if (DICT_ROOT.equals(parentCode)) {
|
||||
// 根节点parent_code=project
|
||||
rootList.add(dict);
|
||||
} else {
|
||||
DictProject parent = dictMap.get(parentCode);
|
||||
if (parent != null) {
|
||||
if (parent.getChildren() == null) {
|
||||
parent.setChildren(new ArrayList<>());
|
||||
}
|
||||
parent.getChildren().add(dict);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 保证children字段始终存在
|
||||
for (DictProject dict : allList) {
|
||||
if (dict.getChildren() == null) {
|
||||
dict.setChildren(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
return rootList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insertDictProject(DictProject dictProject) {
|
||||
if (dictProject.getId() == null && dictProject.getParentCode() == null) {
|
||||
dictProject.setParentCode(DICT_ROOT);
|
||||
dictProject.setParentType("-1=-2");
|
||||
}
|
||||
return this.saveOrUpdate(dictProject);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import com.coscoshipping.ebtp.system.menu.vo.MenuTreeVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
/**
|
||||
* 菜单信息
|
||||
@ -127,6 +130,14 @@ public class SysMenuController extends BaseController {
|
||||
return BaseResponse.success(tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有菜单树形结构,供角色分配权限时选择
|
||||
*/
|
||||
@GetMapping("/treeAll")
|
||||
public BaseResponse<List<MenuTreeVO>> getAllMenuTree() {
|
||||
return BaseResponse.success(menuService.getAllMenuTree());
|
||||
}
|
||||
|
||||
@GetMapping(value = "/expert/role/menu")
|
||||
public BaseResponse<List<BaseRoleTabulation>> getBaseRoleTabulation(@RequestParam("userId") String userId) {
|
||||
return BaseResponse.success(menuService.getBaseRoleTabulation(userId));
|
||||
|
@ -7,6 +7,7 @@ import com.coscoshipping.ebtp.system.login.entity.EshopMenuQuery;
|
||||
import com.coscoshipping.ebtp.system.menu.dto.BaseRoleTabulation;
|
||||
import com.coscoshipping.ebtp.system.menu.entity.SysMenu;
|
||||
import com.coscoshipping.ebtp.system.menu.entity.TreeSelect;
|
||||
import com.coscoshipping.ebtp.system.menu.vo.MenuTreeVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -161,4 +162,10 @@ public interface ISysMenuService
|
||||
* @update [序号][日期YYYY-MM-DD] [更改人姓名][变更描述]
|
||||
*/
|
||||
List<EshopMenuConverter> findMenuList(EshopMenuQuery body) throws BusinessException;
|
||||
|
||||
/**
|
||||
* 获取所有菜单的树形结构,供角色分配权限时选择
|
||||
* @return 菜单树结构
|
||||
*/
|
||||
List<MenuTreeVO> getAllMenuTree();
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import com.coscoshipping.ebtp.system.login.entity.EshopMenuConverterChildren;
|
||||
import com.coscoshipping.ebtp.system.menu.vo.MenuTreeVO;
|
||||
|
||||
/**
|
||||
* 菜单 业务层处理
|
||||
@ -450,4 +451,31 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||
// 根节点的 children 字段已初始化为空
|
||||
return rootMenus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuTreeVO> getAllMenuTree() {
|
||||
List<SysMenu> menus = selectMenuList(new SysMenu(), null);
|
||||
List<SysMenu> tree = buildMenuTree(menus);
|
||||
List<MenuTreeVO> voList = new ArrayList<>();
|
||||
for (SysMenu menu : tree) {
|
||||
voList.add(convertToMenuTreeVO(menu));
|
||||
}
|
||||
return voList;
|
||||
}
|
||||
|
||||
private MenuTreeVO convertToMenuTreeVO(SysMenu menu) {
|
||||
MenuTreeVO vo = new MenuTreeVO();
|
||||
vo.setId(menu.getMenuId());
|
||||
vo.setParentId(menu.getParentId());
|
||||
vo.setLabel(menu.getMenuName());
|
||||
vo.setWeight(menu.getMenuOrder());
|
||||
if (menu.getChildren() != null && !menu.getChildren().isEmpty()) {
|
||||
List<MenuTreeVO> children = new ArrayList<>();
|
||||
for (SysMenu child : menu.getChildren()) {
|
||||
children.add(convertToMenuTreeVO(child));
|
||||
}
|
||||
vo.setChildren(children);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
<result column="branch" jdbcType="INTEGER" property="branch" />
|
||||
<result column="site" jdbcType="VARCHAR" property="site" />
|
||||
<result column="cu_company_number" jdbcType="VARCHAR" property="cuCompanyNumber" />
|
||||
<result column="cu_company_name" jdbcType="VARCHAR" property="cuCompanyName" />
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
|
||||
<result column="create_date" jdbcType="VARCHAR" property="createDate" />
|
||||
<result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
|
||||
@ -47,7 +48,7 @@
|
||||
org_id, org_name, org_num, org_full_id, org_full_name,
|
||||
up_org_id, org_category, leader_name, leader_oa_code, leader_user_id,
|
||||
top_leader_name, top_leader_oa_code, top_leader_user_id, sort, status,
|
||||
branch, site, cu_company_number, create_by, create_date, tenant_id,
|
||||
branch, site, cu_company_number, cu_company_name, create_by, create_date, tenant_id,
|
||||
tenant_name, update_by, update_date, delete_flag, last_update_time,
|
||||
1 as level
|
||||
FROM sys_org
|
||||
@ -60,7 +61,7 @@
|
||||
o.org_id, o.org_name, o.org_num, o.org_full_id, o.org_full_name,
|
||||
o.up_org_id, o.org_category, o.leader_name, o.leader_oa_code, o.leader_user_id,
|
||||
o.top_leader_name, o.top_leader_oa_code, o.top_leader_user_id, o.sort, o.status,
|
||||
o.branch, o.site, o.cu_company_number, o.create_by, o.create_date, o.tenant_id,
|
||||
o.branch, o.site, o.cu_company_number, o.cu_company_name, o.create_by, o.create_date, o.tenant_id,
|
||||
o.tenant_name, o.update_by, o.update_date, o.delete_flag, o.last_update_time,
|
||||
ot.level + 1
|
||||
FROM sys_org o
|
||||
@ -70,7 +71,7 @@
|
||||
org_id, org_name, org_num, org_full_id, org_full_name,
|
||||
up_org_id, org_category, leader_name, leader_oa_code, leader_user_id,
|
||||
top_leader_name, top_leader_oa_code, top_leader_user_id, sort, status,
|
||||
branch, site, cu_company_number, create_by, create_date, tenant_id,
|
||||
branch, site, cu_company_number, cu_company_name, create_by, create_date, tenant_id,
|
||||
tenant_name, update_by, update_date, delete_flag, last_update_time
|
||||
FROM org_tree
|
||||
ORDER BY sort ASC, org_name ASC
|
||||
|
@ -76,10 +76,11 @@ public class SysOrg extends BaseEntity implements Serializable {
|
||||
@ApiModelProperty(value = "省份简称")
|
||||
private String site;
|
||||
|
||||
@ApiModelProperty(value = "所属分公司编码")
|
||||
@ApiModelProperty(value = "所属公司编码")
|
||||
private String cuCompanyNumber;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "所属公司名称")
|
||||
private String cuCompanyName;
|
||||
|
||||
@ApiModelProperty(value = "租户ID")
|
||||
private String tenantId;
|
||||
|
@ -38,4 +38,7 @@ public class SysOrgVO extends SysOrg implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "树形结构所有部门ID")
|
||||
private String allDepartmentId;
|
||||
|
||||
@ApiModelProperty(value = "所属公司名称")
|
||||
private String cuCompanyName;
|
||||
}
|
||||
|
Reference in New Issue
Block a user