xiaochen %!s(int64=2) %!d(string=hai) anos
pai
achega
24ebc49101

+ 11 - 0
src/main/java/com/tld/controller/MenuController.java

@@ -89,5 +89,16 @@ public class MenuController {
         return menuService.getUserMenuPDA(userId);
     }
 
+    /** 
+    * @Description: 根据用户查询菜单内容PC
+    * @Param: userId  参数
+    * @return: 返回结果
+    * @Author: XiaoChen
+    * @Date: 2023/5/6
+    */
+    @GetMapping("getUserMenuPc")
+    public Map<String, Object> getUserMenuPc(String userId){
+        return menuService.getUserMenuPc(userId);
+    }
 
 }

+ 3 - 0
src/main/java/com/tld/mapper/MenuMapper.java

@@ -2,6 +2,7 @@ package com.tld.mapper;
 
 import com.tld.model.Menu;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -20,4 +21,6 @@ public interface MenuMapper {
     List<Menu> getPage(Menu menu);
 
     List<Menu> getUserMenuPDA(String userId);
+
+    List<Menu> getUserMenuPc(@Param("userId") String userId);
 }

+ 4 - 0
src/main/java/com/tld/model/User.java

@@ -80,6 +80,10 @@ public class User implements Serializable {
      * 菜单
      */
     private String menu;
+    /**
+     * 前段用
+     */
+    private String menuBefore;
     /**
      * 修改人
      */

+ 2 - 0
src/main/java/com/tld/service/MenuService.java

@@ -19,4 +19,6 @@ public interface MenuService {
     Map<String, Object> getPage(Menu menu);
 
     Map<String, Object> getUserMenuPDA(String userId);
+
+    Map<String, Object> getUserMenuPc(String userId);
 }

+ 15 - 0
src/main/java/com/tld/service/impl/DictionaryServiceImpl.java

@@ -13,6 +13,8 @@ import com.tld.util.RedisUtil;
 import com.tld.util.SnowflakeUtil;
 import org.apache.ibatis.jdbc.Null;
 import org.apache.poi.ss.formula.functions.T;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -33,6 +35,9 @@ public class DictionaryServiceImpl implements DictionaryService {
     private DictionaryMapper dictionaryMapper;
     @Autowired
     private RedisUtil redisUtil;
+    //redis锁
+    @Autowired
+    private RedissonClient redissonClient;
 
     //雪花算法
     private SnowflakeUtil snowflakeUtil = new SnowflakeUtil(1, 1, 1);
@@ -41,6 +46,9 @@ public class DictionaryServiceImpl implements DictionaryService {
     @Transactional(rollbackFor = Exception.class)
     public Map<String, Object> addDictionary(List<Dictionary> dictionarys) {
         Map<String, Object> map = new HashMap<>();
+//        //redis并发锁
+//        RLock lock = redissonClient.getLock(null);
+//        lock.lock();
         boolean flg = false;
         try {
             for (Dictionary dictionary : dictionarys) {
@@ -90,6 +98,13 @@ public class DictionaryServiceImpl implements DictionaryService {
             map.put("status", "0009");
             map.put("msg", "服务器请求异常,请稍后再试");
         }
+//        finally {
+//            //判断要解锁的key是否已被锁定;判断要解锁的key是否被当前线程持有
+//            if (lock.isLocked() && lock.isHeldByCurrentThread()) {
+//                //释放锁
+//                lock.unlock();
+//            }
+//        }
         return map;
     }
 

+ 42 - 0
src/main/java/com/tld/service/impl/MenuServiceImpl.java

@@ -135,6 +135,48 @@ public class MenuServiceImpl implements MenuService {
         return map;
     }
 
+    /**
+     * @Description: 根据用户查询菜单内容PC
+     * @Param: userId  参数
+     * @return: 返回结果
+     * @Author: XiaoChen
+     * @Date: 2023/5/6
+     */
+    @Override
+    public Map<String, Object> getUserMenuPc(String userId) {
+        Map<String, Object> map = new HashMap<>();
+        try{
+            //查询用户菜单
+            List<Menu> list = menuMapper.getUserMenuPc(userId);
+            //根据角色查询用户菜单权限
+            List<Menu> list1 = menuMapper.getUserMenu(userId);
+
+            ArrayList<Menu> menus = new ArrayList<>();
+            HashSet<String> ids = new HashSet<>();
+
+            for (Menu menu : list) {
+                if (!ids.contains(menu.getId())){
+                    menus.add(menu);
+                    ids.add(menu.getId());
+                }
+            }
+            for (Menu menu : list1) {
+                if (!ids.contains(menu.getId())){
+                    menus.add(menu);
+                    ids.add(menu.getId());
+                }
+            }
+
+            map.put("data", menus);
+            map.put("msg", "200");
+        }catch (Exception e){
+            e.printStackTrace();
+            map.put("msg", "500");
+            map.put("errMsg", "服务器请求异常,请稍后再试");
+        }
+        return map;
+    }
+
     /**
      * 树结构查询
      * @return

+ 12 - 0
src/main/resources/mapper/MenuMapper.xml

@@ -115,4 +115,16 @@
         WHERE c.menu_pda LIKE CONCAT('%', CONCAT(a.id, ','), '%')
         ORDER BY a.order_by
     </select>
+    <!--根据用户查询菜单内容PC-->
+    <select id="getUserMenuPc" resultType="com.tld.model.Menu">
+        SELECT a.id,
+               a.name,
+               a.url,
+               a.img,
+               a.p_id,
+               b.menu
+        FROM tld_menu a
+        JOIN tld_user b on b.id = #{userId}
+        where b.menu like CONCAT('%', CONCAT(a.id, ','), '%')
+    </select>
 </mapper>

+ 8 - 0
src/main/resources/mapper/UserMapper.xml

@@ -39,6 +39,8 @@
             c.name as department,
             b.role_name as role,
             a.role as roleId,
+            a.menu,
+            a.menu_before,
             a.department as departmentId,
             a.modify_time as modifyTime,
             f.user_name as modifyUser
@@ -117,6 +119,12 @@
                 <if test="department != null">
                     department = #{department},
                 </if>
+                <if test="menu != null">
+                    menu = #{menu},
+                </if>
+                <if test="menuBefore != null">
+                    menu_before = #{menuBefore},
+                </if>
                 <if test="role != null">
                     role = #{role},
                 </if>