项目为maven管理,数据库mysql,idea平台开发,有学生,老师,管理员三个角色,平台有权限校验,数据库一共有25张表。配合当下的学生招聘需求,快速实现岗位实习或就业定位,岗位推荐用协同过滤算法处理,项目每个操作都是可以通过auth配置权限。我的联系方式在最下方。
功能如下:
- 学生用户管理
- 教师用户管理
- 宣讲信息管理
- 招聘信息管理
- 岗位类别管理
- 简历投递管理
- 确认录用管理
- 实习签到管理
- 实习周报管理
- 周报批改管理
- 我的收藏管理
- 评论管理
- 公告管理
- 学生实习管理
- 轮播图管理
图示:
部分代码:
用户登录注册代码逻辑
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.teaopenapi.models.Config;
import com.project.demo.context.TenantContext;
import com.project.demo.entity.AccessToken;
import com.project.demo.entity.User;
import com.project.demo.entity.UserGroup;
import com.project.demo.entity.base.DataHolder;
import com.project.demo.service.UserGroupService;
import com.project.demo.service.UserService;
import com.project.demo.controller.base.BaseController;
import com.project.demo.util.RsaUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
/**
* 用户账户:用于保存用户登录信息(User)表控制层
*/
@Slf4j
@RestController
@RequestMapping("user")
public class UserController extends BaseController<User, UserService> {
/**
* 服务对象
*/
@Autowired
public UserController(UserService service) {
setService(service);
}
@Autowired
private DataHolder dataHolder;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private UserGroupService userGroupService;
@Autowired
private RedisTemplate redisTemplate;
/**
* 注册
*
* @param user
* @return
*/
@PostMapping("register")
public Map<String, Object> signUp(@RequestBody User user) {
// 查询用户
Map<String, String> query = new HashMap<>();
Map<String, Object> map = JSON.parseObject(JSON.toJSONString(user));
query.put("username", user.getUsername());
List list = service.selectBaseList(service.select(query, new HashMap<>()));
if (list.size() > 0) {
return error(30000, "用户已存在");
}
map.put("password", service.encryption(String.valueOf(map.get("password"))));
service.insert(map);
return success(1);
}
/**
* 找回密码
*
* @param form
* @return
*/
@PostMapping("forget_password")
public Map<String, Object> forgetPassword(@RequestBody User form, HttpServletRequest request) {
String username = form.getUsername();
String code = form.getCode();
String password = form.getPassword();
// TenantDTO tenantDTO = TenantContext.get();
String result = dataHolder.getData();
// 判断条件
if (code == null || code.length() == 0) {
return error(30000, "验证码不能为空");
}
// !code.equals(tenantDTO.getMsgCode())
if (!code.equals(result)) {
return error(30000, "验证码错误");
}
if (username == null || username.length() == 0) {
return error(30000, "用户名不能为空");
}
if (password == null || password.length() == 0) {
return error(30000, "密码不能为空");
}
TenantContext.remove();
// 查询用户
Map<String, String> query = new HashMap<>();
query.put("username", username);
List list = service.selectBaseList(service.select(query, service.readConfig(request)));
if (list.size() > 0) {
User o = (User) list.get(0);
JSONObject query2 = new JSONObject();
JSONObject form2 = new JSONObject();
// 修改用户密码
query2.put("user_id", o.getUserId());
form2.put("password", service.encryption(password));
service.update(query, service.readConfig(request), form2);
return success(1);
}
return error(70000, "用户不存在");
}
/**
* 登录
*
* @param data
* @param httpServletRequest
* @return
*/
@PostMapping("login")
public Map<String, Object> login(@RequestBody Map<String, String> data, HttpServletRequest httpServletRequest) {
log.info("[执行登录接口]");
String username = data.get("username");
String email = data.get("email");
String phone = data.get("phone");
String password = data.get("password");
try {
password = RsaUtils.decryptByPrivateKey(password);
} catch (Exception e) {
return error(30000, "解密失败");
}
List resultList = null;
Map<String, String> map = new HashMap<>();
if (username != null && "".equals(username) == false) {
map.put("username", username);
resultList = service.selectBaseList(service.select(map, new HashMap<>()));
} else if (email != null && "".equals(email) == false) {
map.put("email", email);
resultList = service.selectBaseList(service.select(map, new HashMap<>()));
} else if (phone != null && "".equals(phone) == false) {
map.put("phone", phone);
resultList = service.selectBaseList(service.select(map, new HashMap<>()));
} else {
return error(30000, "账号或密码不能为空");
}
if (resultList == null || password == null) {
return error(30000, "账号或密码不能为空");
}
//判断是否有这个用户
if (resultList.size() <= 0) {
return error(30000, "用户不存在");
}
User byUsername = (User) resultList.get(0);
Map<String, String> groupMap = new HashMap<>();
groupMap.put("name", byUsername.getUserGroup());
List groupList = userGroupService.selectBaseList(userGroupService.select(groupMap, new HashMap<>()));
if (groupList.size() < 1) {
return error(30000, "用户组不存在");
}
UserGroup userGroup = (UserGroup) groupList.get(0);
//查询用户审核状态
if (!StringUtils.isEmpty(userGroup.getSourceTable())) {
String res = service.selectExamineState(userGroup.getSourceTable(), byUsername.getUserId());
if (res == null) {
return error(30000, "用户不存在");
}
if (!res.equals("已通过")) {
return error(30000, "该用户审核未通过");
}
}
//查询用户状态
if (byUsername.getState() != 1) {
return error(30000, "用户非可用状态,不能登录");
}
String face = data.get("is_face");
String md5password = service.encryption(password);
if (!StringUtils.isEmpty(face) && face.equals("face")) {
if (byUsername.getPassword().equals(md5password)) {
// 返回用户信息
JSONObject user = JSONObject.parseObject(JSONObject.toJSONString(byUsername));
JSONObject ret = new JSONObject();
ret.put("obj", user);
return success(ret);
} else {
return error(30000, "账号或密码不正确");
}
} else {
if (byUsername.getPassword().equals(md5password)) {
// 存储Token到数据库
AccessToken accessToken = new AccessToken();
accessToken.setToken(UUID.randomUUID().toString().replaceAll("-", ""));
accessToken.setUser_id(byUsername.getUserId());
Duration duration = Duration.ofSeconds(7200L);
redisTemplate.opsForValue().set(accessToken.getToken(), accessToken, duration);
// 返回用户信息
JSONObject user = JSONObject.parseObject(JSONObject.toJSONString(byUsername));
user.put("token", accessToken.getToken());
JSONObject ret = new JSONObject();
ret.put("obj", user);
return success(ret);
} else {
return error(30000, "账号或密码不正确");
}
}
}
/**
* 修改密码
*
* @param data
* @param request
* @return
*/
@PostMapping("change_password")
public Map<String, Object> change_password(@RequestBody Map<String, String> data, HttpServletRequest request) {
// 根据Token获取UserId
String token = request.getHeader("x-auth-token");
Integer userId = tokenGetUserId(token);
// 根据UserId和旧密码获取用户
Map<String, String> query = new HashMap<>();
String o_password = data.get("o_password");
query.put("user_id", String.valueOf(userId));
query.put("password", service.encryption(o_password));
int count = service.selectBaseCount(service.count(query, service.readConfig(request)));
if (count > 0) {
// 修改密码
Map<String, Object> form = new HashMap<>();
form.put("password", service.encryption(data.get("password")));
service.update(query, service.readConfig(request), form);
return success(1);
}
return error(10000, "密码修改失败!");
}
/**
* 登录态
*
* @param request
* @return
*/
@GetMapping("state")
public Map<String, Object> state(HttpServletRequest request) {
JSONObject ret = new JSONObject();
// 获取状态
String token = request.getHeader("x-auth-token");
// 根据登录态获取用户ID
Integer userId = tokenGetUserId(token);
log.info("[返回userId] {}", userId);
if (userId == null || userId == 0) {
return error(10000, "用户未登录!");
}
// 根据用户ID获取用户
Map<String, String> query = new HashMap<>();
query.put("user_id", String.valueOf(userId));
// 根据用户ID获取
List resultList = service.selectBaseList(service.select(query, service.readConfig(request)));
if (resultList.size() > 0) {
JSONObject user = JSONObject.parseObject(JSONObject.toJSONString(resultList.get(0)));
user.put("token", token);
ret.put("obj", user);
return success(ret);
} else {
return error(10000, "用户未登录!");
}
}
/**
* 登录态
*
* @param request
* @return
*/
@GetMapping("quit")
public Map<String, Object> quit(HttpServletRequest request) {
String token = request.getHeader("x-auth-token");
try {
redisTemplate.delete(token);
} catch (Exception e) {
e.printStackTrace();
}
return success("退出登录成功!");
}
/**
* 获取登录用户ID
*
* @param token
* @return
*/
public Integer tokenGetUserId(String token) {
log.info("[获取的token] {}", token);
// 根据登录态获取用户ID
if (token == null || "".equals(token)) {
return 0;
}
AccessToken byToken = (AccessToken) redisTemplate.opsForValue().get(token);
if (byToken == null) {
return 0;
}
return byToken.getUser_id();
}
/**
* 重写add
*
* @return
*/
@PostMapping("/add")
@Transactional
public Map<String, Object> add(HttpServletRequest request) throws IOException {
Map<String, Object> map = service.readBody(request.getReader());
map.put("password", service.encryption(String.valueOf(map.get("password"))));
service.insert(map);
return success(1);
}
}
表auth (用户权限管理)
编号 | 名称 | 数据类型 | 长度 | 小数位 | 允许空值 | 主键 | 默认值 | 说明 |
1 | auth_id | int | 10 | 0 | N | Y | 授权ID: | |
2 | user_group | varchar | 64 | 0 | Y | N | 用户组: | |
3 | mod_name | varchar | 64 | 0 | Y | N | 模块名: | |
4 | table_name | varchar | 64 | 0 | Y | N | 表名: | |
5 | page_title | varchar | 255 | 0 | Y | N | 页面标题: | |
6 | path | varchar | 255 | 0 | Y | N | 路由路径: | |
7 | position | varchar | 32 | 0 | Y | N | 位置: | |
8 | mode | varchar | 32 | 0 | N | N | _blank | 跳转方式: |
9 | add | tinyint | 3 | 0 | N | N | 1 | 是否可增加: |
10 | del | tinyint | 3 | 0 | N | N | 1 | 是否可删除: |
11 | set | tinyint | 3 | 0 | N | N | 1 | 是否可修改: |
12 | get | tinyint | 3 | 0 | N | N | 1 | 是否可查看: |
13 | field_add | text | 65535 | 0 | Y | N | 添加字段: | |
14 | field_set | text | 65535 | 0 | Y | N | 修改字段: | |
15 | field_get | text | 65535 | 0 | Y | N | 查询字段: | |
16 | table_nav_name | varchar | 500 | 0 | Y | N | 跨表导航名称: | |
17 | table_nav | varchar | 500 | 0 | Y | N | 跨表导航: | |
18 | option | text | 65535 | 0 | Y | N | 配置: | |
19 | create_time | timestamp | 19 | 0 | N | N | CURRENT_TIMESTAMP | 创建时间: |
20 | update_time | timestamp | 19 | 0 | N | N | CURRENT_TIMESTAMP | 更新时间: |
表collect (收藏)
编号 | 名称 | 数据类型 | 长度 | 小数位 | 允许空值 | 主键 | 默认值 | 说明 |
1 | collect_id | int | 10 | 0 | N | Y | 收藏ID: | |
2 | user_id | int | 10 | 0 | N | N | 0 | 收藏人ID: |
3 | source_table | varchar | 255 | 0 | Y | N | 来源表: | |
4 | source_field | varchar | 255 | 0 | Y | N | 来源字段: | |
5 | source_id | int | 10 | 0 | N | N | 0 | 来源ID: |
6 | title | varchar | 255 | 0 | Y | N | 标题: | |
7 | img | varchar | 255 | 0 | Y | N | 封面: | |
8 | create_time | timestamp | 19 | 0 | N | N | CURRENT_TIMESTAMP | 创建时间: |
9 | update_time | timestamp | 19 | 0 | N | N | CURRENT_TIMESTAMP | 更新时间: |
表comment (评论)
编号 | 名称 | 数据类型 | 长度 | 小数位 | 允许空值 | 主键 | 默认值 | 说明 |
1 | comment_id | int | 10 | 0 | N | Y | 评论ID: | |
2 | user_id | int | 10 | 0 | N | N | 0 | 评论人ID: |
3 | reply_to_id | int | 10 | 0 | N | N | 0 | 回复评论ID:空为0 |
4 | content | longtext | 2147483647 | 0 | Y | N | 内容: | |
5 | nickname | varchar | 255 | 0 | Y | N | 昵称: | |
6 | avatar | varchar | 255 | 0 | Y | N | 头像地址:[0,255] | |
7 | create_time | timestamp | 19 | 0 | N | N | CURRENT_TIMESTAMP | 创建时间: |
8 | update_time | timestamp | 19 | 0 | N | N | CURRENT_TIMESTAMP | 更新时间: |
9 | source_table | varchar | 255 | 0 | Y | N | 来源表: | |
10 | source_field | varchar | 255 | 0 | Y | N | 来源字段: | |
11 | source_id | int | 10 | 0 | N | N | 0 | 来源ID: |
需要项目可扫码私聊我,调试和讲解,二开代码都能与我联系: