Commit c01b3aec authored by liboyang's avatar liboyang

新增用户登录功能,返回该用户的角色以及各角色对应的权限列表

parent beb817e4
......@@ -58,11 +58,6 @@
<!--<artifactId>spring-boot-starter-log4j2</artifactId>-->
<!--</dependency>-->
<!--引入jersey作为http rest接口实现-->
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-jersey</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -9,7 +9,7 @@ import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class YxRefactoringApplication {
public class Main {
@Bean
public ServletRegistrationBean jerseyServlet() {
......@@ -20,6 +20,6 @@ public class YxRefactoringApplication {
}
public static void main(String[] args) {
SpringApplication.run(YxRefactoringApplication.class, args);
SpringApplication.run(Main.class, args);
}
}
......@@ -4,11 +4,14 @@ import com.yx_project.start.entity.SystemUserEntity;
import com.yx_project.start.service.impl.SystemUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Path("user")
public class SystemUserApi {
......@@ -16,11 +19,29 @@ public class SystemUserApi {
@Autowired
private SystemUserServiceImpl userService;
/**
* 用户登陆返回该用户的功能列表
*
*/
@GET
@Path("list")
@Path("UserLogin")
@Produces(MediaType.APPLICATION_JSON)
public List<SystemUserEntity> list(){
List<SystemUserEntity> list = userService.findAllUser();
return list;
public Map<String, Object> userLogin(@QueryParam("username") String username, @QueryParam("password") String password, @Context HttpServletResponse response) {
response.setCharacterEncoding("UTF-8");
Map<String,String> userMap = new HashMap();
userMap.put("username",username);
userMap.put("password",password);
SystemUserEntity user = userService.findUserRoleMenu(userMap);
Map<String,Object> returnMap = new HashMap<>();
if(user==null){
returnMap.put("returnCode", "0");
returnMap.put("returnMsg", "用户名或密码错误");
return returnMap;
} else {
returnMap.put("returnCode", "1");
returnMap.put("returnMsg", "登陆成功");
returnMap.put("user", user);
return returnMap;
}
}
}
package com.yx_project.start.entity;
import javax.persistence.*;
@Entity
@Table(name = "SYSTEM_MENU", schema = "DAHAI", catalog = "")
public class SystemMenuEntity {
private long menuId;
private String menu;
private String menuName;
@Id
@Column(name = "MENU_ID")
public long getMenuId() {
return menuId;
}
......@@ -19,8 +14,7 @@ public class SystemMenuEntity {
this.menuId = menuId;
}
@Basic
@Column(name = "MENU")
public String getMenu() {
return menu;
}
......@@ -29,8 +23,7 @@ public class SystemMenuEntity {
this.menu = menu;
}
@Basic
@Column(name = "MENU_NAME")
public String getMenuName() {
return menuName;
}
......@@ -39,25 +32,4 @@ public class SystemMenuEntity {
this.menuName = menuName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SystemMenuEntity that = (SystemMenuEntity) o;
if (menuId != that.menuId) return false;
if (menu != null ? !menu.equals(that.menu) : that.menu != null) return false;
if (menuName != null ? !menuName.equals(that.menuName) : that.menuName != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (menuId ^ (menuId >>> 32));
result = 31 * result + (menu != null ? menu.hashCode() : 0);
result = 31 * result + (menuName != null ? menuName.hashCode() : 0);
return result;
}
}
......@@ -3,23 +3,22 @@ package com.yx_project.start.entity;
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "SYSTEM_ROLE", schema = "DAHAI", catalog = "")
public class SystemRoleEntity {
private long roleId;
private String roleName;
// private List<SystemMenuEntity> menuEntityList;
//
// public List<SystemMenuEntity> getMenuEntityList() {
// return menuEntityList;
// }
//
// public void setMenuEntityList(List<SystemMenuEntity> menuEntityList) {
// this.menuEntityList = menuEntityList;
// }
@Id
@Column(name = "ROLE_ID")
private List<SystemMenuEntity> menuEntityList;
public List<SystemMenuEntity> getMenuEntityList() {
return menuEntityList;
}
public void setMenuEntityList(List<SystemMenuEntity> menuEntityList) {
this.menuEntityList = menuEntityList;
}
public long getRoleId() {
return roleId;
}
......@@ -28,8 +27,7 @@ public class SystemRoleEntity {
this.roleId = roleId;
}
@Basic
@Column(name = "ROLE_NAME")
public String getRoleName() {
return roleName;
}
......@@ -38,23 +36,4 @@ public class SystemRoleEntity {
this.roleName = roleName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SystemRoleEntity that = (SystemRoleEntity) o;
if (roleId != that.roleId) return false;
if (roleName != null ? !roleName.equals(that.roleName) : that.roleName != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (roleId ^ (roleId >>> 32));
result = 31 * result + (roleName != null ? roleName.hashCode() : 0);
return result;
}
}
......@@ -5,35 +5,32 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "SYSTEM_ROLE_MENU", schema = "DAHAI", catalog = "")
public class SystemRoleMenuEntity {
private long systemRoleMenuId;
private long roleMenuId;
private long roleId;
@Id
@Column(name = "SYSTEM_ROLE_MENU_ID")
public long getSystemRoleMenuId() {
return systemRoleMenuId;
public long getRoleId() {
return roleId;
}
public void setSystemRoleMenuId(long systemRoleMenuId) {
this.systemRoleMenuId = systemRoleMenuId;
public void setRoleId(long roleId) {
this.roleId = roleId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SystemRoleMenuEntity that = (SystemRoleMenuEntity) o;
public long getRoleMenuId() {
return roleMenuId;
}
if (systemRoleMenuId != that.systemRoleMenuId) return false;
public void setRoleMenuId(long roleMenuId) {
this.roleMenuId = roleMenuId;
}
return true;
public long getSystemRoleMenuId() {
return systemRoleMenuId;
}
@Override
public int hashCode() {
return (int) (systemRoleMenuId ^ (systemRoleMenuId >>> 32));
public void setSystemRoleMenuId(long systemRoleMenuId) {
this.systemRoleMenuId = systemRoleMenuId;
}
}
package com.yx_project.start.entity;
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "SYSTEM_USER", schema = "DAHAI", catalog = "")
public class SystemUserEntity {
private long id;
private String username;
private String password;
private String workshop;
// private List<SystemRoleEntity> roleEntityList;
//
// public List<SystemRoleEntity> getRoleEntityList() {
// return roleEntityList;
// }
//
// public void setRoleEntityList(List<SystemRoleEntity> roleEntityList) {
// this.roleEntityList = roleEntityList;
// }
@Id
@Column(name = "ID")
private long roleId;
private List<SystemRoleEntity> roleEntityList;
public long getRoleId() {
return roleId;
}
public void setRoleId(long roleId) {
this.roleId = roleId;
}
public List<SystemRoleEntity> getRoleEntityList() {
return roleEntityList;
}
public void setRoleEntityList(List<SystemRoleEntity> roleEntityList) {
this.roleEntityList = roleEntityList;
}
public long getId() {
return id;
}
......@@ -30,8 +35,7 @@ public class SystemUserEntity {
this.id = id;
}
@Basic
@Column(name = "USERNAME")
public String getUsername() {
return username;
}
......@@ -40,8 +44,6 @@ public class SystemUserEntity {
this.username = username;
}
@Basic
@Column(name = "PASSWORD")
public String getPassword() {
return password;
}
......@@ -50,8 +52,7 @@ public class SystemUserEntity {
this.password = password;
}
@Basic
@Column(name = "WORKSHOP")
public String getWorkshop() {
return workshop;
}
......@@ -59,28 +60,4 @@ public class SystemUserEntity {
public void setWorkshop(String workshop) {
this.workshop = workshop;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SystemUserEntity that = (SystemUserEntity) o;
if (id != that.id) return false;
if (username != null ? !username.equals(that.username) : that.username != null) return false;
if (password != null ? !password.equals(that.password) : that.password != null) return false;
if (workshop != null ? !workshop.equals(that.workshop) : that.workshop != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (username != null ? username.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (workshop != null ? workshop.hashCode() : 0);
return result;
}
}
......@@ -6,10 +6,8 @@ import java.util.List;
import java.util.Map;
@Mapper
public interface SystemUserMapper {
public interface SystemUserMapper {
public List<SystemUserEntity> findAll();
// public SystemUserEntity selectByUsernameAndPassword(Map<String,String> map);
}
public SystemUserEntity findUserRoleMenu(Map<String,String> map);
}
......@@ -6,9 +6,6 @@ import java.util.List;
import java.util.Map;
public interface SystemUserService {
/**
* 根据接口查询所用的用户
*/
public List<SystemUserEntity> findAllUser();
// public SystemUserEntity findUserRoleMenu(Map<String,String> map);
public SystemUserEntity findUserRoleMenu(Map<String,String> map);
}
......@@ -14,12 +14,13 @@ public class SystemUserServiceImpl implements SystemUserService {
@Autowired
private SystemUserMapper systemUserMapper;
@Override
public List<SystemUserEntity> findAllUser() {
List<SystemUserEntity> list = systemUserMapper.findAll();
return list;
}
public SystemUserEntity findUserRoleMenu(Map<String, String> map) {
SystemUserEntity user = systemUserMapper.findUserRoleMenu(map);
return user;
}
}
<?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.yx_project.start.mapper.SystemUserMapper">
<!--&lt;!&ndash;用户&ndash;&gt;-->
<!--<resultMap id="UserRoleMenuMap" type="com.yx_project.start.entity.SystemUserEntity">-->
<!--<id property="id" column="id"/>-->
<!--<result column="username" property="username"/>-->
<!--<result column="password" property="password"/>-->
<!--<result column="workshop" property="workshop"/>-->
<!--&lt;!&ndash;角色集合&ndash;&gt;-->
<!--<collection property="roleEntityList" ofType="SystemRoleEntity" column="id" select="selectAllRole"/>-->
<!--</resultMap>-->
<!--&lt;!&ndash;角色&ndash;&gt;-->
<!--<resultMap id="RoleMap" type="com.yx_project.start.entity.SystemRoleEntity" >-->
<!--<id column="roleId" property="roleId" />-->
<!--<result column="roleName" property="roleName"/>-->
<!--&lt;!&ndash;权限集合&ndash;&gt;-->
<!--<collection property="menuEntityList" ofType="SystemMenuEntity" column="id" select="selectAllMenu"/>-->
<!--</resultMap>-->
<!--&lt;!&ndash;权限&ndash;&gt;-->
<!--<resultMap id="MenuMap" type="com.yx_project.start.entity.SystemMenuEntity" >-->
<!--<id column="menuId" property="menuId" />-->
<!--<result column="menu" property="menu"/>-->
<!--<result column="menuName" property="menuName"/>-->
<!--</resultMap>-->
<!--用户-->
<resultMap id="UserRoleMenuMap" type="com.yx_project.start.entity.SystemUserEntity">
<id property="id" column="id"/>
<result column="uname" property="username"/>
<result column="upass" property="password"/>
<result column="workshop" property="workshop"/>
<!--角色集合-->
<collection property="roleEntityList" ofType="com.yx_project.start.entity.SystemRoleEntity">
<id column="rid" property="roleId" />
<result column="rname" property="roleName"/>
<!--权限集合-->
<collection property="menuEntityList" ofType="com.yx_project.start.entity.SystemMenuEntity">
<id column="mid" property="menuId" />
<result column="mname" property="menuName"/>
<result column="menu" property="menu"/>
</collection>
</collection>
</resultMap>
<select id="findAll" resultType="SystemUserEntity">
select * from "SYSTEM_USER"
</select>
<!--&lt;!&ndash;根据角色id查询权限(先从角色权限关联表查询角色id相等,在查询权限id,根据权限id在权限表里查询权限)&ndash;&gt;-->
<!--<select id="selectAllMenu" resultType="com.yx_project.start.entity.SystemMenuEntity" parameterType="java.lang.Integer">-->
<!--select menuId,menuName from SYSTEM_MENU where menuId in (select SYSTEM_ROLE_MENU.ROLE_MENU_ID from SYSTEM_ROLE_MENU where SYSTEM_ROLE_MENU.ROLE_ID=#{id})-->
<!--</select>-->
<!--&lt;!&ndash;查询所有角色&ndash;&gt;-->
<!--<select id="selectAllRole" resultMap="RoleMap" parameterType="java.lang.Integer">-->
<!--select roleId,roleName from SYSTEM_ROLE where roleId in (select "SYSTEM_USER".ROLE_ID from "SYSTEM_USER" where "SYSTEM_USER".id=#{id})-->
<!--</select>-->
<!--&lt;!&ndash;通过用户名密码查询用户&ndash;&gt;-->
<!--<select id="selectByUsernameAndPassword" resultMap="UserRoleMenuMap" parameterType="Map">-->
<!--select * from user where username=#{username} AND password = #{password}-->
<!--</select>-->
<select id="findUserRoleMenu" resultMap="UserRoleMenuMap" parameterType="map">
select "SYSTEM_USER".id,SYSTEM_USER.username as uname,SYSTEM_USER.password as upass,SYSTEM_USER.workshop,SYSTEM_ROLE.role_id as rid,SYSTEM_ROLE.role_name as rname,
SYSTEM_MENU.MENU_ID mid,SYSTEM_MENU.MENU_NAME mname,SYSTEM_MENU.MENU
from "SYSTEM_USER"
left join SYSTEM_ROLE on SYSTEM_USER.role_id = SYSTEM_ROLE.ROLE_ID
left join SYSTEM_ROLE_MENU on SYSTEM_ROLE.ROLE_ID = SYSTEM_ROLE_MENU.ROLE_ID
left join SYSTEM_MENU on SYSTEM_ROLE_MENU.ROLE_MENU_ID = SYSTEM_MENU.MENU_ID
where username=#{username} and password=#{password}
</select>
</mapper>
\ No newline at end of file
......@@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class YxRefactoringApplicationTests {
public class MainTests {
@Test
public void contextLoads() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment