From cd1a68f15e107f036d9c265db88bc775a36f43c7 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期四, 13 一月 2022 10:26:18 +0800
Subject: [PATCH] update 防止 MP 无主键警告

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java |   39 +++++++++++++++++----------------------
 1 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
index cea08c8..f3c4a74 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
@@ -6,10 +6,8 @@
 import com.ruoyi.common.core.domain.PageQuery;
 import com.ruoyi.common.core.domain.entity.SysRole;
 import com.ruoyi.common.core.domain.entity.SysUser;
-import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.exception.ServiceException;
-import com.ruoyi.common.utils.PageUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.spring.SpringUtils;
@@ -21,7 +19,7 @@
 import com.ruoyi.system.mapper.SysRoleMenuMapper;
 import com.ruoyi.system.mapper.SysUserRoleMapper;
 import com.ruoyi.system.service.ISysRoleService;
-import org.springframework.beans.factory.annotation.Autowired;
+import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -32,22 +30,19 @@
  *
  * @author Lion Li
  */
+@RequiredArgsConstructor
 @Service
-public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole, SysRole> implements ISysRoleService {
+public class SysRoleServiceImpl implements ISysRoleService {
 
-    @Autowired
-    private SysRoleMenuMapper roleMenuMapper;
-
-    @Autowired
-    private SysUserRoleMapper userRoleMapper;
-
-    @Autowired
-    private SysRoleDeptMapper roleDeptMapper;
+    private final SysRoleMapper baseMapper;
+    private final SysRoleMenuMapper roleMenuMapper;
+    private final SysUserRoleMapper userRoleMapper;
+    private final SysRoleDeptMapper roleDeptMapper;
 
     @Override
     public TableDataInfo<SysRole> selectPageRoleList(SysRole role, PageQuery pageQuery) {
-        Page<SysRole> page = baseMapper.selectPageRoleList(PageUtils.buildPage(pageQuery), role);
-        return PageUtils.buildDataInfo(page);
+        Page<SysRole> page = baseMapper.selectPageRoleList(pageQuery.build(), role);
+        return TableDataInfo.build(page);
     }
 
     /**
@@ -129,7 +124,7 @@
      */
     @Override
     public SysRole selectRoleById(Long roleId) {
-        return getById(roleId);
+        return baseMapper.selectById(roleId);
     }
 
     /**
@@ -141,10 +136,10 @@
     @Override
     public String checkRoleNameUnique(SysRole role) {
         Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
-        long count = count(new LambdaQueryWrapper<SysRole>()
+        boolean count = baseMapper.exists(new LambdaQueryWrapper<SysRole>()
                 .eq(SysRole::getRoleName, role.getRoleName())
                 .ne(SysRole::getRoleId, roleId));
-        if (count > 0) {
+        if (count) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
@@ -159,10 +154,10 @@
     @Override
     public String checkRoleKeyUnique(SysRole role) {
         Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
-        long count = count(new LambdaQueryWrapper<SysRole>()
+        boolean count = baseMapper.exists(new LambdaQueryWrapper<SysRole>()
                 .eq(SysRole::getRoleKey, role.getRoleKey())
                 .ne(SysRole::getRoleId, roleId));
-        if (count > 0) {
+        if (count) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
@@ -282,7 +277,7 @@
             list.add(rm);
         }
         if (list.size() > 0) {
-            rows = roleMenuMapper.insertAll(list);
+            rows = roleMenuMapper.insertBatch(list) ? list.size() : 0;
         }
         return rows;
     }
@@ -303,7 +298,7 @@
             list.add(rd);
         }
         if (list.size() > 0) {
-            rows = roleDeptMapper.insertAll(list);
+            rows = roleDeptMapper.insertBatch(list) ? list.size() : 0;
         }
         return rows;
     }
@@ -394,7 +389,7 @@
             list.add(ur);
         }
         if (list.size() > 0) {
-            rows = userRoleMapper.insertAll(list);
+            rows = userRoleMapper.insertBatch(list) ? list.size() : 0;
         }
         return rows;
     }

--
Gitblit v1.9.3