Commit c01b3aec authored by liboyang's avatar liboyang

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

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