浏览代码

项目搭建

6 年之前
父节点
当前提交
ccc9f9f28d

+ 7 - 0
pcbms/pom.xml

@@ -96,6 +96,13 @@
             <version>3.8.1</version>
         </dependency>
 
+        <!-- https://mvnrepository.com/artifact/io.swagger/swagger-annotations -->
+        <dependency>
+            <groupId>io.swagger</groupId>
+            <artifactId>swagger-annotations</artifactId>
+            <version>1.5.15</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 2 - 0
pcbms/src/main/java/com/hssx/pcbms/PcbmsApplication.java

@@ -1,6 +1,7 @@
 package com.hssx.pcbms;
 
 import com.github.pagehelper.PageHelper;
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.Bean;
@@ -8,6 +9,7 @@ import org.springframework.context.annotation.Bean;
 import java.util.Properties;
 
 @SpringBootApplication
+@MapperScan("com.hssx.pcbms.mapper")
 public class PcbmsApplication {
 
     public static void main(String[] args) {

+ 22 - 6
pcbms/src/main/java/com/hssx/pcbms/service/impl/RoleServiceImpl.java

@@ -2,8 +2,10 @@ package com.hssx.pcbms.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.hssx.pcbms.entity.Role;
+import com.hssx.pcbms.entity.RolePermission;
 import com.hssx.pcbms.entity.User;
 import com.hssx.pcbms.mapper.RoleMapper;
+import com.hssx.pcbms.mapper.RolePermissionMapper;
 import com.hssx.pcbms.mapper.UserMapper;
 import com.hssx.pcbms.service.RoleService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -24,16 +26,29 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
     private RoleMapper roleMapper;
     @Resource
     private UserMapper userMapper;
+    @Resource
+    private RolePermissionMapper rolePermissionMapper;
 
     @Override
     public HttpRespMsg add(Role role) {
         HttpRespMsg msg = new HttpRespMsg();
-        List<Role> roles = roleMapper.selectList(new QueryWrapper<>(role).last("limit 1"));
-        if (roles.size() > 0) {
-            msg.setError("该角色已存在,请勿重复添加");
-            return msg;
+        if(null == role.getId()){
+            List<Role> roles = roleMapper.selectList(new QueryWrapper<>(role).last("limit 1"));
+            if (roles.size() > 0) {
+                msg.setError("该角色已存在,请勿重复添加");
+                return msg;
+            }
+            //添加
+            roleMapper.insert(role);
+        }else{
+            //修改
+            List<Role> roles = roleMapper.selectList(new QueryWrapper<Role>().eq("name",role.getName()).last("limit 1"));
+            if (roles.size() > 0) {
+                msg.setError("该角色已存在,请修改成其他角色名后再操作");
+                return msg;
+            }
+            roleMapper.updateById(role);
         }
-        roleMapper.insert(role);
         return msg;
     }
 
@@ -46,6 +61,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
             return msg;
         }
         roleMapper.deleteById(role.getId());
-        return null;
+        rolePermissionMapper.delete(new QueryWrapper<RolePermission>().eq("role_id",role.getId()));
+        return msg;
     }
 }

+ 1 - 1
pcbms/src/main/java/com/hssx/pcbms/service/impl/UserServiceImpl.java

@@ -51,7 +51,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             //验证密码是否正确
             if (MD5Util.getPassword(user.getPassword()).equals(systemUser.getPassword()) || sysPwd.equals(user.getPassword())) {
                 UserVO vo = userMapper.selectUserRolesAndPermisssuons(systemUser);
-                msg.data = systemUser;
+                msg.data = vo;
             } else {
                 msg.setError("密码错误");
             }

+ 2 - 5
pcbms/src/main/resources/mapper/UserMapper.xml

@@ -24,15 +24,12 @@
         <result column="role_id" property="roleId" />
         <result column="is_pass" property="isPass" />
         <result column="indate" property="indate" />
-        <result column="password" property="password" />
+        <!--<result column="password" property="password" />-->
         <collection property="permissions" ofType="com.hssx.pcbms.entity.Permission">
-            <id column="id" property="id" />
             <result column="permission_name" property="permissionName" />
         </collection>
         <collection property="roles" ofType="com.hssx.pcbms.entity.Role">
-            <id column="id" property="id" />
             <result column="rolename" property="name" />
-            <result column="indate" property="indate" />
         </collection>
     </resultMap>
 
@@ -41,7 +38,7 @@
         id, head_url, name, phone, dept_id, role_id, is_pass, indate, password
     </sql>
 
-    <select id="selectUserRolesAndPermisssuons">
+    <select id="selectUserRolesAndPermisssuons" resultMap="BaseResultMapVO">
         select
             u.id, u.head_url, u.name, u.phone, u.dept_id, u.role_id, u.is_pass, u.indate,
             p.permission_name,r.name rolename

+ 1 - 6
pom.xml

@@ -37,18 +37,13 @@
             <artifactId>mysql-connector-java</artifactId>
             <scope>runtime</scope>
         </dependency>
+
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
             <optional>true</optional>
         </dependency>
 
-        <!-- https://mvnrepository.com/artifact/io.swagger/swagger-annotations -->
-        <dependency>
-            <groupId>io.swagger</groupId>
-            <artifactId>swagger-annotations</artifactId>
-            <version>1.5.15</version>
-        </dependency>
 
         <dependency>
             <groupId>org.springframework.boot</groupId>