Kaynağa Gözat

菜单接口修改

brealinxx 1 yıl önce
ebeveyn
işleme
bfc90f290a

+ 42 - 21
src/main/java/com/xjrsoft/module/system/controller/MenuController.java

@@ -2,6 +2,7 @@ package com.xjrsoft.module.system.controller;
 
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -10,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.yulichang.toolkit.MPJWrappers;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.jdcloud.sdk.utils.StringUtils;
 import com.xjrsoft.common.constant.GlobalConstant;
 import com.xjrsoft.common.enums.AuthorizeType;
@@ -21,24 +23,11 @@ import com.xjrsoft.common.model.result.R;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.utils.TreeUtil;
 import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.module.organization.entity.Department;
 import com.xjrsoft.module.organization.service.IUserRoleRelationService;
-import com.xjrsoft.module.system.dto.AddMenuDto;
-import com.xjrsoft.module.system.dto.AddMenuFormDto;
-import com.xjrsoft.module.system.dto.MenuTreeDto;
-import com.xjrsoft.module.system.dto.RoleMenuServeListDto;
-import com.xjrsoft.module.system.dto.UpdateMenuDto;
-import com.xjrsoft.module.system.dto.UpdateMenuFormDto;
-import com.xjrsoft.module.system.entity.Authorize;
-import com.xjrsoft.module.system.entity.Menu;
-import com.xjrsoft.module.system.entity.MenuButton;
-import com.xjrsoft.module.system.entity.MenuColumn;
-import com.xjrsoft.module.system.entity.MenuForm;
-import com.xjrsoft.module.system.entity.Subsystem;
-import com.xjrsoft.module.system.service.IAuthorizeService;
-import com.xjrsoft.module.system.service.IMenuButtonService;
-import com.xjrsoft.module.system.service.IMenuColumnService;
-import com.xjrsoft.module.system.service.IMenuFormService;
-import com.xjrsoft.module.system.service.IMenuService;
+import com.xjrsoft.module.system.dto.*;
+import com.xjrsoft.module.system.entity.*;
+import com.xjrsoft.module.system.service.*;
 import com.xjrsoft.module.system.vo.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -56,6 +45,7 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -82,6 +72,8 @@ public class MenuController {
 
     private final IAuthorizeService authorizeService;
 
+    private final IXjrMenuDeptRelationService xjrMenuDeptRelationService;
+
     private final IUserRoleRelationService userRoleRelationService;
 
     @GetMapping("/list")
@@ -140,8 +132,7 @@ public class MenuController {
         if (StrUtil.isEmpty(dto.getSystemType())) {
             dto.setSystemType(SystemTypeEnum.SYSTEMPC.getCode());
         }
-        List<MenuTreeVo> list = menuService.selectJoinList(MenuTreeVo.class,
-                MPJWrappers.<Menu>lambdaJoin()
+        MPJLambdaWrapper<Menu> wrapper = MPJWrappers.<Menu>lambdaJoin()
                         .like(StrUtil.isNotEmpty(dto.getTitle()), Menu::getTitle, dto.getTitle())
                         .like(StrUtil.isNotEmpty(dto.getName()), Menu::getName, dto.getName())
                         .like(ObjectUtil.isNotNull(dto.getSystemId()) && dto.getSystemId() > 0, Menu::getSystemId, dto.getSystemId())
@@ -150,13 +141,29 @@ public class MenuController {
                         .select(Menu.class, x -> VoToColumnUtil.fieldsToColumns(MenuTreeVo.class).contains(x.getProperty()))
                         .selectAs(Subsystem::getName, MenuTreeVo::getSystemName)
                         .eq(ObjectUtils.isNotEmpty(dto.getEnabledMark()), Menu::getEnabledMark, dto.getEnabledMark())
-                        .leftJoin(Subsystem.class, Subsystem::getId, Menu::getSystemId)
-                        .orderByAsc(Menu::getSortCode));
+                        .leftJoin(Subsystem.class, Subsystem::getId, Menu::getSystemId);
+
+//        wrapper.selectAs(Department::getName, MenuTreeVo::getDeptName)
+//                .leftJoin(XjrMenuDeptRelation.class, XjrMenuDeptRelation::getMenuId,Menu::getId)
+//                .leftJoin(Department.class, Department::getId, XjrMenuDeptRelation::getDeptId);
+//
+//        if (StrUtil.isNotEmpty(dto.getDeptIds())) {
+//            String[] deptIdArray = dto.getDeptIds().split(",");
+//            List<String> deptIdList = Arrays.asList(deptIdArray);
+//
+//            if (CollectionUtil.isNotEmpty(deptIdList)) {
+//                wrapper.in(XjrMenuDeptRelation::getDeptId, deptIdList);
+//            }
+//        }
+        wrapper.orderByAsc(Menu::getSortCode);
+
+        List<MenuTreeVo> list = menuService.selectJoinList(MenuTreeVo.class, wrapper);
         List<MenuTreeVo> treeVoList = TreeUtil.build(list);
 
         return R.ok(treeVoList);
     }
 
+
     @GetMapping("/child-tree")
     @ApiOperation(value = "获取所有菜单(树结构,禁用父级)")
     public R menuChildTree(@Valid MenuTreeDto dto) {
@@ -246,6 +253,13 @@ public class MenuController {
         menuFormService.remove(Wrappers.<MenuForm>query().lambda().eq(MenuForm::getMenuId, menu.getId()));
         menuFormService.saveBatch(formList);
 
+        List<XjrMenuDeptRelation> menuDeptRelationsList = new ArrayList<>();
+        for (AddXjrMenuDeptRelationDto addXjrMenuDeptRelationDto : dto.getMenuDeptRelations()) {
+            menuDeptRelationsList.add(BeanUtil.toBean(addXjrMenuDeptRelationDto, XjrMenuDeptRelation.class));
+        }
+        menuDeptRelationsList.forEach(XjrMenuDeptRelation -> XjrMenuDeptRelation.setMenuId(menu.getId()));
+        xjrMenuDeptRelationService.remove(Wrappers.<XjrMenuDeptRelation>query().lambda().eq(XjrMenuDeptRelation::getMenuId, menu.getId()));
+        xjrMenuDeptRelationService.saveBatch(menuDeptRelationsList);
 
         return R.ok(isSuccess);
     }
@@ -304,6 +318,10 @@ public class MenuController {
         formList.forEach(menuForm -> menuForm.setMenuId(menu.getId()));
         menuFormService.remove(Wrappers.<MenuForm>query().lambda().eq(MenuForm::getMenuId, menu.getId()));
 
+        List<XjrMenuDeptRelation> menuDeptRelations = BeanUtil.copyToList(dto.getMenuDeptRelations(), XjrMenuDeptRelation.class);
+        menuDeptRelations.forEach(XjrMenuDeptRelation -> XjrMenuDeptRelation.setMenuId(menu.getId()));
+        xjrMenuDeptRelationService.remove(Wrappers.<XjrMenuDeptRelation>query().lambda().eq(XjrMenuDeptRelation::getMenuId, menu.getId()));
+
         if (CollectionUtils.isNotEmpty(menuButtons)) {
             menuButtonService.saveBatch(menuButtons);
         }
@@ -313,6 +331,9 @@ public class MenuController {
         if (CollectionUtils.isNotEmpty(formList)) {
             menuFormService.saveBatch(formList);
         }
+        if (CollectionUtils.isNotEmpty(menuDeptRelations)) {
+            xjrMenuDeptRelationService.saveBatch(menuDeptRelations);
+        }
         return R.ok();
     }
 

+ 1 - 1
src/main/java/com/xjrsoft/module/system/controller/XjrMenuDeptRelationController.java

@@ -75,7 +75,7 @@ public class XjrMenuDeptRelationController {
     public RT<Boolean> add(@Valid @RequestBody AddXjrMenuDeptRelationDto dto){
         XjrMenuDeptRelation xjrMenuDeptRelation = BeanUtil.toBean(dto, XjrMenuDeptRelation.class);
         boolean isSuccess = xjrMenuDeptRelationService.save(xjrMenuDeptRelation);
-    return RT.ok(isSuccess);
+        return RT.ok(isSuccess);
     }
 
     @PutMapping

+ 3 - 0
src/main/java/com/xjrsoft/module/system/dto/AddMenuDto.java

@@ -1,5 +1,6 @@
 package com.xjrsoft.module.system.dto;
 
+import com.xjrsoft.module.system.entity.XjrMenuDeptRelation;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import org.hibernate.validator.constraints.Length;
@@ -106,4 +107,6 @@ public class AddMenuDto implements Serializable {
     @ApiModelProperty("表单字段列表")
     private List<AddMenuFormDto> formList;
 
+    @ApiModelProperty("菜单部门关联表")
+    private List<AddXjrMenuDeptRelationDto> menuDeptRelations;
 }

+ 3 - 0
src/main/java/com/xjrsoft/module/system/dto/MenuTreeDto.java

@@ -33,4 +33,7 @@ public class MenuTreeDto {
 
     // 菜单是否显示 0=隐藏 1=显示
     private Integer display = 1;
+
+    @ApiModelProperty("部门ID")
+    private String deptIds;
 }

+ 2 - 1
src/main/java/com/xjrsoft/module/system/dto/UpdateMenuDto.java

@@ -116,5 +116,6 @@ public class UpdateMenuDto implements Serializable {
     @ApiModelProperty("表单字段列表")
     private List<UpdateMenuFormDto> formList;
 
-
+    @ApiModelProperty("菜单部门关联表")
+    private List<UpdateXjrMenuDeptRelationDto> menuDeptRelations;
 }

+ 4 - 0
src/main/java/com/xjrsoft/module/system/mapper/XjrMenuQuickMapper.java

@@ -2,8 +2,11 @@ package com.xjrsoft.module.system.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.xjrsoft.module.system.entity.XjrMenuQuick;
+import com.xjrsoft.module.system.vo.MenuTreeVo;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
 * @title: 快捷菜单
 * @Author fanxp
@@ -13,4 +16,5 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface XjrMenuQuickMapper extends BaseMapper<XjrMenuQuick> {
 
+    List<MenuTreeVo> selectAllList(List<String> deptIdList);
 }

+ 3 - 0
src/main/java/com/xjrsoft/module/system/service/IMenuService.java

@@ -6,6 +6,7 @@ import com.xjrsoft.module.system.dto.RoleMenuServeListDto;
 import com.xjrsoft.module.system.entity.Menu;
 import com.xjrsoft.module.system.vo.MenuAllServeVo;
 import com.xjrsoft.module.system.vo.MenuServeVo;
+import com.xjrsoft.module.system.vo.MenuTreeVo;
 import com.xjrsoft.module.system.vo.MenuVo;
 
 import java.util.List;
@@ -29,4 +30,6 @@ public interface IMenuService extends MPJBaseService<Menu> {
     List<MenuServeVo> getRoleMenuServe(RoleMenuServeListDto dto);
 
     List<Menu> getUserQuick(MenuTreeDto dto);
+
+    List<MenuTreeVo> selectAllist(List<String> deptIdList);
 }

+ 5 - 0
src/main/java/com/xjrsoft/module/system/service/impl/MenuServiceImpl.java

@@ -155,6 +155,11 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
         return menus;
     }
 
+    @Override
+    public List<MenuTreeVo> selectAllist(List<String> deptIdList) {
+        return menuQuickMapper.selectAllList(deptIdList);
+    }
+
     /**
      * 根据角色获取菜单
      *

+ 2 - 0
src/main/java/com/xjrsoft/module/system/vo/MenuTreeVo.java

@@ -138,6 +138,8 @@ public class MenuTreeVo implements ITreeNode<MenuTreeVo,Long>, Serializable {
 
     private Integer enabledMark;
 
+    private String deptName;
+
     private List<MenuTreeVo> children;
 
     private Boolean disabled;

+ 31 - 0
src/main/resources/mapper/asset/XjrMenuQuickMapper.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.xjrsoft.module.system.mapper.XjrMenuQuickMapper">
+    <select id="selectAllList" parameterType="com.xjrsoft.module.system.dto.MenuTreeDto" resultType="com.xjrsoft.module.system.vo.MenuTreeVo">
+        SELECT
+            id, title, name, system_id, system_type, enabled_mark,
+            (SELECT column_name FROM table_name WHERE condition) AS system_name,
+            (SELECT column_name FROM table_name WHERE condition) AS dept_name
+        FROM xjr_menu
+        <where>
+            <if test="title != null and title != ''">
+                AND title LIKE #{title}
+            </if>
+            <if test="name != null and name != ''">
+                AND name LIKE #{name}
+            </if>
+            <if test="systemId != null and systemId > 0">
+                AND system_id = #{systemId}
+            </if>
+            <if test="systemType != null and systemType != ''">
+                AND system_type = #{systemType}
+            </if>
+            <if test="enabledMark != null">
+                AND enabled_mark = #{enabledMark}
+            </if>
+        </where>
+        ORDER BY sort_code ASC
+    </select>
+</mapper>