我的活动,最常访问关注,修改密码
This commit is contained in:
parent
a76e5306cf
commit
5ea2d62f7f
@ -1,9 +1,6 @@
|
|||||||
package org.jeecg.modules.aiol.controller;
|
package org.jeecg.modules.aiol.controller;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@ -13,8 +10,11 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.system.query.QueryGenerator;
|
import org.jeecg.common.system.query.QueryGenerator;
|
||||||
import org.jeecg.common.system.query.QueryRuleEnum;
|
import org.jeecg.common.system.query.QueryRuleEnum;
|
||||||
|
import org.jeecg.common.system.util.JwtUtil;
|
||||||
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.common.util.oConvertUtils;
|
||||||
|
import org.jeecg.modules.aiol.entity.AiolActivity;
|
||||||
import org.jeecg.modules.aiol.entity.AiolActivitySignup;
|
import org.jeecg.modules.aiol.entity.AiolActivitySignup;
|
||||||
|
import org.jeecg.modules.aiol.service.IAiolActivityService;
|
||||||
import org.jeecg.modules.aiol.service.IAiolActivitySignupService;
|
import org.jeecg.modules.aiol.service.IAiolActivitySignupService;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
@ -22,6 +22,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import org.jeecg.modules.system.entity.SysUser;
|
||||||
|
import org.jeecg.modules.system.service.impl.SysUserServiceImpl;
|
||||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||||
@ -51,6 +53,10 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|||||||
public class AiolActivitySignupController extends JeecgController<AiolActivitySignup, IAiolActivitySignupService> {
|
public class AiolActivitySignupController extends JeecgController<AiolActivitySignup, IAiolActivitySignupService> {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAiolActivitySignupService aiolActivitySignupService;
|
private IAiolActivitySignupService aiolActivitySignupService;
|
||||||
|
@Autowired
|
||||||
|
private SysUserServiceImpl sysUserService;
|
||||||
|
@Autowired
|
||||||
|
private IAiolActivityService aiolActivityService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页列表查询
|
* 分页列表查询
|
||||||
@ -75,7 +81,7 @@ public class AiolActivitySignupController extends JeecgController<AiolActivitySi
|
|||||||
IPage<AiolActivitySignup> pageList = aiolActivitySignupService.page(page, queryWrapper);
|
IPage<AiolActivitySignup> pageList = aiolActivitySignupService.page(page, queryWrapper);
|
||||||
return Result.OK(pageList);
|
return Result.OK(pageList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加
|
* 添加
|
||||||
*
|
*
|
||||||
@ -91,7 +97,7 @@ public class AiolActivitySignupController extends JeecgController<AiolActivitySi
|
|||||||
|
|
||||||
return Result.OK("添加成功!");
|
return Result.OK("添加成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑
|
* 编辑
|
||||||
*
|
*
|
||||||
@ -106,7 +112,7 @@ public class AiolActivitySignupController extends JeecgController<AiolActivitySi
|
|||||||
aiolActivitySignupService.updateById(aiolActivitySignup);
|
aiolActivitySignupService.updateById(aiolActivitySignup);
|
||||||
return Result.OK("编辑成功!");
|
return Result.OK("编辑成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过id删除
|
* 通过id删除
|
||||||
*
|
*
|
||||||
@ -121,7 +127,7 @@ public class AiolActivitySignupController extends JeecgController<AiolActivitySi
|
|||||||
aiolActivitySignupService.removeById(id);
|
aiolActivitySignupService.removeById(id);
|
||||||
return Result.OK("删除成功!");
|
return Result.OK("删除成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除
|
* 批量删除
|
||||||
*
|
*
|
||||||
@ -136,7 +142,7 @@ public class AiolActivitySignupController extends JeecgController<AiolActivitySi
|
|||||||
this.aiolActivitySignupService.removeByIds(Arrays.asList(ids.split(",")));
|
this.aiolActivitySignupService.removeByIds(Arrays.asList(ids.split(",")));
|
||||||
return Result.OK("批量删除成功!");
|
return Result.OK("批量删除成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过id查询
|
* 通过id查询
|
||||||
*
|
*
|
||||||
@ -179,4 +185,37 @@ public class AiolActivitySignupController extends JeecgController<AiolActivitySi
|
|||||||
return super.importExcel(request, response, AiolActivitySignup.class);
|
return super.importExcel(request, response, AiolActivitySignup.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//查看我报名的活动
|
||||||
|
@GetMapping(value = "/queryMyActivity")
|
||||||
|
@Operation(summary="我的活动查询")
|
||||||
|
public Result<List<AiolActivity>> queryMyActivit(HttpServletRequest req) {
|
||||||
|
try {
|
||||||
|
// 1. 从JWT中获取当前用户信息
|
||||||
|
String username = JwtUtil.getUserNameByToken(req);
|
||||||
|
if (username == null || username.trim().isEmpty()) {
|
||||||
|
return Result.error(401, "用户未登录或token无效");
|
||||||
|
}
|
||||||
|
SysUser currentUser = sysUserService.getUserByName(username);
|
||||||
|
if (currentUser == null) {
|
||||||
|
return Result.error(404, "用户不存在");
|
||||||
|
}
|
||||||
|
// 2. 根据当前用户ID查询报名信息
|
||||||
|
QueryWrapper<AiolActivitySignup> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("user_id", currentUser.getId());
|
||||||
|
List<AiolActivitySignup> list = aiolActivitySignupService.list(queryWrapper);
|
||||||
|
// 3. 根据报名信息中的活动ID查询活动信息
|
||||||
|
List<AiolActivity> activityList = new ArrayList<>();
|
||||||
|
List<String> activityIds = list.stream()
|
||||||
|
.map(AiolActivitySignup::getActivityId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (!activityIds.isEmpty()) {
|
||||||
|
activityList = aiolActivityService.listByIds(activityIds);
|
||||||
|
}
|
||||||
|
return Result.OK(activityList);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("查询失败: {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return Result.OK();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||||
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.common.constant.CommonConstant;
|
||||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||||
import org.jeecg.common.system.util.JwtUtil;
|
import org.jeecg.common.system.util.JwtUtil;
|
||||||
@ -212,24 +213,24 @@ public class AiolUserController {
|
|||||||
try {
|
try {
|
||||||
// 构建查询条件
|
// 构建查询条件
|
||||||
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
// 只查询教师角色的用户
|
// 只查询教师角色的用户
|
||||||
queryWrapper.inSql(SysUser::getId,
|
queryWrapper.inSql(SysUser::getId,
|
||||||
"SELECT user_id FROM sys_user_role WHERE role_id = '1955367301787348993'"); // 教师角色ID
|
"SELECT user_id FROM sys_user_role WHERE role_id = '1955367301787348993'"); // 教师角色ID
|
||||||
|
|
||||||
// 可选条件:按姓名查询
|
// 可选条件:按姓名查询
|
||||||
if (realName != null && !realName.trim().isEmpty()) {
|
if (realName != null && !realName.trim().isEmpty()) {
|
||||||
queryWrapper.like(SysUser::getRealname, realName.trim());
|
queryWrapper.like(SysUser::getRealname, realName.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 可选条件:按工号查询
|
// 可选条件:按工号查询
|
||||||
if (workNo != null && !workNo.trim().isEmpty()) {
|
if (workNo != null && !workNo.trim().isEmpty()) {
|
||||||
queryWrapper.like(SysUser::getWorkNo, workNo.trim());
|
queryWrapper.like(SysUser::getWorkNo, workNo.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询用户列表
|
// 查询用户列表
|
||||||
List<SysUser> teachers = sysUserService.list(queryWrapper);
|
List<SysUser> teachers = sysUserService.list(queryWrapper);
|
||||||
|
|
||||||
// 构建返回结果
|
// 构建返回结果
|
||||||
List<Map<String, Object>> result = teachers.stream().map(teacher -> {
|
List<Map<String, Object>> result = teachers.stream().map(teacher -> {
|
||||||
Map<String, Object> teacherInfo = new LinkedHashMap<>();
|
Map<String, Object> teacherInfo = new LinkedHashMap<>();
|
||||||
@ -242,7 +243,7 @@ public class AiolUserController {
|
|||||||
teacherInfo.put("avatar", teacher.getAvatar());
|
teacherInfo.put("avatar", teacher.getAvatar());
|
||||||
teacherInfo.put("status", teacher.getStatus());
|
teacherInfo.put("status", teacher.getStatus());
|
||||||
teacherInfo.put("createTime", teacher.getCreateTime());
|
teacherInfo.put("createTime", teacher.getCreateTime());
|
||||||
|
|
||||||
// 查询扩展信息
|
// 查询扩展信息
|
||||||
AiolUserInfo userInfo = userInfoMapper.selectOne(
|
AiolUserInfo userInfo = userInfoMapper.selectOne(
|
||||||
new QueryWrapper<AiolUserInfo>().eq("user_id", teacher.getId()));
|
new QueryWrapper<AiolUserInfo>().eq("user_id", teacher.getId()));
|
||||||
@ -253,12 +254,12 @@ public class AiolUserController {
|
|||||||
teacherInfo.put("title", userInfo.getTitle());
|
teacherInfo.put("title", userInfo.getTitle());
|
||||||
teacherInfo.put("tag", userInfo.getTag());
|
teacherInfo.put("tag", userInfo.getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
return teacherInfo;
|
return teacherInfo;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
return Result.OK(result);
|
return Result.OK(result);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("查询教师用户失败: realName={}, workNo={}, error={}", realName, workNo, e.getMessage(), e);
|
log.error("查询教师用户失败: realName={}, workNo={}, error={}", realName, workNo, e.getMessage(), e);
|
||||||
return Result.error("查询教师用户失败: " + e.getMessage());
|
return Result.error("查询教师用户失败: " + e.getMessage());
|
||||||
@ -271,13 +272,13 @@ public class AiolUserController {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Result<JSONObject> studentRegister(@RequestBody Map<String, String> registerData) {
|
public Result<JSONObject> studentRegister(@RequestBody Map<String, String> registerData) {
|
||||||
Result<JSONObject> result = new Result<>();
|
Result<JSONObject> result = new Result<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 1. 获取注册参数
|
// 1. 获取注册参数
|
||||||
String studentNumber = registerData.get("studentNumber");
|
String studentNumber = registerData.get("studentNumber");
|
||||||
String inviteCode = registerData.get("inviteCode");
|
String inviteCode = registerData.get("inviteCode");
|
||||||
String password = registerData.get("password");
|
String password = registerData.get("password");
|
||||||
|
|
||||||
// 2. 参数验证
|
// 2. 参数验证
|
||||||
if (studentNumber == null || studentNumber.trim().isEmpty()) {
|
if (studentNumber == null || studentNumber.trim().isEmpty()) {
|
||||||
return result.error500("学号不能为空");
|
return result.error500("学号不能为空");
|
||||||
@ -288,13 +289,13 @@ public class AiolUserController {
|
|||||||
if (password == null || password.trim().isEmpty()) {
|
if (password == null || password.trim().isEmpty()) {
|
||||||
return result.error500("密码不能为空");
|
return result.error500("密码不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 检查学号是否已被注册
|
// 3. 检查学号是否已被注册
|
||||||
SysUser existingUser = sysUserService.getUserByName(studentNumber);
|
SysUser existingUser = sysUserService.getUserByName(studentNumber);
|
||||||
if (existingUser != null) {
|
if (existingUser != null) {
|
||||||
return result.error500("学号已被注册,请使用其他学号");
|
return result.error500("学号已被注册,请使用其他学号");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 检查邀请码是否对应某个班级
|
// 4. 检查邀请码是否对应某个班级
|
||||||
LambdaQueryWrapper<AiolClass> classQuery = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<AiolClass> classQuery = new LambdaQueryWrapper<>();
|
||||||
classQuery.eq(AiolClass::getInviteCode, inviteCode);
|
classQuery.eq(AiolClass::getInviteCode, inviteCode);
|
||||||
@ -303,26 +304,26 @@ public class AiolUserController {
|
|||||||
if (targetClass == null) {
|
if (targetClass == null) {
|
||||||
return result.error500("邀请码无效,请检查邀请码是否正确");
|
return result.error500("邀请码无效,请检查邀请码是否正确");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 使用通用方法创建学生用户
|
// 5. 使用通用方法创建学生用户
|
||||||
SysUser studentUser = sysUserService.createStudentUser(studentNumber, studentNumber, password);
|
SysUser studentUser = sysUserService.createStudentUser(studentNumber, studentNumber, password);
|
||||||
|
|
||||||
// 6. 设置工号(学号)
|
// 6. 设置工号(学号)
|
||||||
studentUser.setWorkNo(studentNumber);
|
studentUser.setWorkNo(studentNumber);
|
||||||
sysUserService.updateById(studentUser);
|
sysUserService.updateById(studentUser);
|
||||||
|
|
||||||
// 7. 自动加入班级
|
// 7. 自动加入班级
|
||||||
AiolClassStudent classStudent = new AiolClassStudent();
|
AiolClassStudent classStudent = new AiolClassStudent();
|
||||||
classStudent.setClassId(targetClass.getId());
|
classStudent.setClassId(targetClass.getId());
|
||||||
classStudent.setStudentId(studentUser.getId());
|
classStudent.setStudentId(studentUser.getId());
|
||||||
classStudent.setCreateBy("system"); // 系统创建
|
classStudent.setCreateBy("system"); // 系统创建
|
||||||
classStudent.setCreateTime(new Date());
|
classStudent.setCreateTime(new Date());
|
||||||
|
|
||||||
boolean classStudentSaved = aiolClassStudentService.save(classStudent);
|
boolean classStudentSaved = aiolClassStudentService.save(classStudent);
|
||||||
if (!classStudentSaved) {
|
if (!classStudentSaved) {
|
||||||
throw new RuntimeException("加入班级失败");
|
throw new RuntimeException("加入班级失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. 构建返回结果
|
// 8. 构建返回结果
|
||||||
JSONObject response = new JSONObject();
|
JSONObject response = new JSONObject();
|
||||||
response.put("userId", studentUser.getId());
|
response.put("userId", studentUser.getId());
|
||||||
@ -331,14 +332,14 @@ public class AiolUserController {
|
|||||||
response.put("classId", targetClass.getId());
|
response.put("classId", targetClass.getId());
|
||||||
response.put("className", targetClass.getName());
|
response.put("className", targetClass.getName());
|
||||||
response.put("message", "注册成功,已自动加入班级:" + targetClass.getName());
|
response.put("message", "注册成功,已自动加入班级:" + targetClass.getName());
|
||||||
|
|
||||||
log.info("学生注册成功: 学号={}, 班级ID={}, 班级名={}",
|
log.info("学生注册成功: 学号={}, 班级ID={}, 班级名={}",
|
||||||
studentNumber, targetClass.getId(), targetClass.getName());
|
studentNumber, targetClass.getId(), targetClass.getName());
|
||||||
|
|
||||||
result.setResult(response);
|
result.setResult(response);
|
||||||
result.success("注册成功");
|
result.success("注册成功");
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("学生注册失败: {}", e.getMessage(), e);
|
log.error("学生注册失败: {}", e.getMessage(), e);
|
||||||
return result.error500("注册失败: " + e.getMessage());
|
return result.error500("注册失败: " + e.getMessage());
|
||||||
@ -355,18 +356,18 @@ public class AiolUserController {
|
|||||||
if (username == null || username.trim().isEmpty()) {
|
if (username == null || username.trim().isEmpty()) {
|
||||||
return Result.error(401, "用户未登录或token无效");
|
return Result.error(401, "用户未登录或token无效");
|
||||||
}
|
}
|
||||||
|
|
||||||
SysUser currentUser = sysUserService.getUserByName(username);
|
SysUser currentUser = sysUserService.getUserByName(username);
|
||||||
if (currentUser == null) {
|
if (currentUser == null) {
|
||||||
return Result.error(404, "用户不存在");
|
return Result.error(404, "用户不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
String id = currentUser.getId();
|
String id = currentUser.getId();
|
||||||
|
|
||||||
// 2. 更新sys_user表的基本信息
|
// 2. 更新sys_user表的基本信息
|
||||||
SysUser userToUpdate = new SysUser();
|
SysUser userToUpdate = new SysUser();
|
||||||
userToUpdate.setId(id);
|
userToUpdate.setId(id);
|
||||||
|
|
||||||
if (profileDTO.getRealname() != null) {
|
if (profileDTO.getRealname() != null) {
|
||||||
userToUpdate.setRealname(profileDTO.getRealname());
|
userToUpdate.setRealname(profileDTO.getRealname());
|
||||||
}
|
}
|
||||||
@ -385,20 +386,20 @@ public class AiolUserController {
|
|||||||
if (profileDTO.getPhone() != null) {
|
if (profileDTO.getPhone() != null) {
|
||||||
userToUpdate.setPhone(profileDTO.getPhone());
|
userToUpdate.setPhone(profileDTO.getPhone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置更新信息
|
// 设置更新信息
|
||||||
userToUpdate.setUpdateBy(username);
|
userToUpdate.setUpdateBy(username);
|
||||||
userToUpdate.setUpdateTime(new Date());
|
userToUpdate.setUpdateTime(new Date());
|
||||||
|
|
||||||
boolean userUpdated = sysUserService.updateById(userToUpdate);
|
boolean userUpdated = sysUserService.updateById(userToUpdate);
|
||||||
if (!userUpdated) {
|
if (!userUpdated) {
|
||||||
return Result.error(500, "更新用户基本信息失败");
|
return Result.error(500, "更新用户基本信息失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 更新aiol_user_info表的扩展信息
|
// 3. 更新aiol_user_info表的扩展信息
|
||||||
AiolUserInfo userInfo = userInfoMapper.selectOne(
|
AiolUserInfo userInfo = userInfoMapper.selectOne(
|
||||||
new QueryWrapper<AiolUserInfo>().eq("user_id", id));
|
new QueryWrapper<AiolUserInfo>().eq("user_id", id));
|
||||||
|
|
||||||
if (userInfo == null) {
|
if (userInfo == null) {
|
||||||
// 如果扩展信息不存在,创建新记录
|
// 如果扩展信息不存在,创建新记录
|
||||||
userInfo = new AiolUserInfo();
|
userInfo = new AiolUserInfo();
|
||||||
@ -406,7 +407,7 @@ public class AiolUserController {
|
|||||||
userInfo.setCreateBy(username);
|
userInfo.setCreateBy(username);
|
||||||
userInfo.setCreateTime(new Date());
|
userInfo.setCreateTime(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新扩展信息字段
|
// 更新扩展信息字段
|
||||||
if (profileDTO.getMajor() != null) {
|
if (profileDTO.getMajor() != null) {
|
||||||
userInfo.setMajor(profileDTO.getMajor());
|
userInfo.setMajor(profileDTO.getMajor());
|
||||||
@ -423,11 +424,11 @@ public class AiolUserController {
|
|||||||
if (profileDTO.getTag() != null) {
|
if (profileDTO.getTag() != null) {
|
||||||
userInfo.setTag(profileDTO.getTag());
|
userInfo.setTag(profileDTO.getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置更新信息
|
// 设置更新信息
|
||||||
userInfo.setUpdateBy(username);
|
userInfo.setUpdateBy(username);
|
||||||
userInfo.setUpdateTime(new Date());
|
userInfo.setUpdateTime(new Date());
|
||||||
|
|
||||||
boolean userInfoUpdated;
|
boolean userInfoUpdated;
|
||||||
if (userInfo.getId() == null) {
|
if (userInfo.getId() == null) {
|
||||||
// 新增记录
|
// 新增记录
|
||||||
@ -436,17 +437,59 @@ public class AiolUserController {
|
|||||||
// 更新记录
|
// 更新记录
|
||||||
userInfoUpdated = userInfoMapper.updateById(userInfo) > 0;
|
userInfoUpdated = userInfoMapper.updateById(userInfo) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userInfoUpdated) {
|
if (!userInfoUpdated) {
|
||||||
return Result.error(500, "更新用户扩展信息失败");
|
return Result.error(500, "更新用户扩展信息失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("用户个人信息更新成功: userId={}, username={}", id, username);
|
log.info("用户个人信息更新成功: userId={}, username={}", id, username);
|
||||||
return Result.OK("个人信息更新成功");
|
return Result.OK("个人信息更新成功");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("编辑个人信息失败: {}", e.getMessage(), e);
|
log.error("编辑个人信息失败: {}", e.getMessage(), e);
|
||||||
return Result.error(500, "编辑个人信息失败: " + e.getMessage());
|
return Result.error(500, "编辑个人信息失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//密码修改
|
||||||
|
@AutoLog(value = "用户信息-修改密码")
|
||||||
|
@Operation(summary="用户信息-修改密码")
|
||||||
|
@PostMapping(value = "/updatePassword")
|
||||||
|
public Result<?> updatePassword(@RequestBody Map<String, String> params, HttpServletRequest request) {
|
||||||
|
try {
|
||||||
|
// 1. 从JWT中获取当前用户信息
|
||||||
|
String username = JwtUtil.getUserNameByToken(request);
|
||||||
|
if (username == null || username.trim().isEmpty()) {
|
||||||
|
return Result.error(401, "用户未登录或token无效");
|
||||||
|
}
|
||||||
|
SysUser currentUser = sysUserService.getUserByName(username);
|
||||||
|
if (currentUser == null) {
|
||||||
|
return Result.error(404, "用户不存在");
|
||||||
|
}
|
||||||
|
String oldPassword = params.get("oldPassword");
|
||||||
|
String newPassword = params.get("newPassword");
|
||||||
|
String id = currentUser.getId();
|
||||||
|
//判断密码是否一致
|
||||||
|
String oldPasswordEncrypt = PasswordUtil.encrypt(username, oldPassword, currentUser.getSalt());
|
||||||
|
String passwordEncrypt = currentUser.getPassword();
|
||||||
|
if (newPassword == null || newPassword.trim().isEmpty()) {
|
||||||
|
return Result.error(400, "新密码不允许为空");
|
||||||
|
}
|
||||||
|
if (newPassword.equals(oldPassword)) {
|
||||||
|
return Result.error(400, "新密码不能与旧密码相同");
|
||||||
|
}
|
||||||
|
if (!oldPasswordEncrypt.equals(passwordEncrypt)) {
|
||||||
|
return Result.error(400, "旧密码不正确");
|
||||||
|
}
|
||||||
|
//更新密码
|
||||||
|
String password = PasswordUtil.encrypt(username, newPassword, currentUser.getSalt());
|
||||||
|
currentUser.setPassword(password);
|
||||||
|
sysUserService.updateById(currentUser);
|
||||||
|
log.info("用户密码修改成功: userId={}, username={}", id, username);
|
||||||
|
return Result.OK("密码修改成功");
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("密码修改失败: {}", e.getMessage(), e);
|
||||||
|
return Result.error(500, "密码修改失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,32 +292,73 @@ public class AiolUserFollowController extends JeecgController<AiolUserFollow, IA
|
|||||||
if (sysUser == null) {
|
if (sysUser == null) {
|
||||||
return Result.error("用户未登录或登录已过期");
|
return Result.error("用户未登录或登录已过期");
|
||||||
}
|
}
|
||||||
// 2. 查询最近关注列表
|
// 2. 查询最近关注列表
|
||||||
String recentFollowKey = "user:recent:follow:" + sysUser.getId();
|
String recentFollowKey = "user:recent:follow:" + sysUser.getId();
|
||||||
Set<Object> objects = redisTemplate.opsForZSet().range(recentFollowKey, 0, -1);
|
Set<Object> objects = redisTemplate.opsForZSet().range(recentFollowKey, 0, -1);
|
||||||
Set<String> followedIds = objects.stream()
|
Set<String> followedIds = objects.stream()
|
||||||
.map(obj -> String.valueOf(obj))
|
.map(obj -> String.valueOf(obj))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
if (followedIds != null && !followedIds.isEmpty()) {
|
if (followedIds != null && !followedIds.isEmpty()) {
|
||||||
// 根据被关注者的ID列表查询用户信息
|
// 根据被关注者的ID列表查询用户信息
|
||||||
List<SysUser> followedUsers = sysUserService.listByIds(followedIds);
|
List<SysUser> followedUsers = sysUserService.listByIds(followedIds);
|
||||||
if (followedUsers != null && !followedUsers.isEmpty()) {
|
if (followedUsers != null && !followedUsers.isEmpty()) {
|
||||||
List<UserFollow> userFollows = new ArrayList<>();
|
List<UserFollow> userFollows = new ArrayList<>();
|
||||||
for (SysUser followedUser : followedUsers) {
|
for (SysUser followedUser : followedUsers) {
|
||||||
UserFollow userFollow = new UserFollow();
|
UserFollow userFollow = new UserFollow();
|
||||||
userFollow.setId(followedUser.getId());
|
userFollow.setId(followedUser.getId());
|
||||||
userFollow.setIsFollow(true);
|
userFollow.setIsFollow(true);
|
||||||
userFollow.setRealName(followedUser.getRealname());
|
userFollow.setRealName(followedUser.getRealname());
|
||||||
userFollow.setAvatar(followedUser.getAvatar());
|
userFollow.setAvatar(followedUser.getAvatar());
|
||||||
userFollows.add(userFollow);
|
userFollows.add(userFollow);
|
||||||
}
|
}
|
||||||
return Result.OK(userFollows);
|
return Result.OK(userFollows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Result.error(e.getMessage());
|
return Result.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return Result.OK();
|
return Result.OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询最常访问
|
||||||
|
@AutoLog(value = "关注关系-查询最常访问")
|
||||||
|
@Operation(summary = "查询最常访问", description = "当前登录用户最常访问的用户")
|
||||||
|
@GetMapping(value = "/frequentVisitList")
|
||||||
|
public Result<List<?>> frequentVisitList(HttpServletRequest req) {
|
||||||
|
try {
|
||||||
|
// 1. 获取当前登录用户信息
|
||||||
|
String token = req.getHeader(CommonConstant.X_ACCESS_TOKEN);
|
||||||
|
String username = JwtUtil.getUsername(token);
|
||||||
|
LoginUser sysUser = sysBaseApi.getUserByName(username);
|
||||||
|
if (sysUser == null) {
|
||||||
|
return Result.error("用户未登录或登录已过期");
|
||||||
|
}
|
||||||
|
// 2. 查询最常访问列表
|
||||||
|
String frequentVisitKey = "user:frequent:visit:" + sysUser.getId();
|
||||||
|
Set<Object> objects = redisTemplate.opsForZSet().range(frequentVisitKey, 0, -1);
|
||||||
|
Set<String> followedIds = objects.stream()
|
||||||
|
.map(obj -> String.valueOf(obj))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
if (followedIds != null && !followedIds.isEmpty()) {
|
||||||
|
// 根据被关注者的ID列表查询用户信息
|
||||||
|
List<SysUser> followedUsers = sysUserService.listByIds(followedIds);
|
||||||
|
if (followedUsers != null && !followedUsers.isEmpty()) {
|
||||||
|
List<UserFollow> userFollows = new ArrayList<>();
|
||||||
|
for (SysUser followedUser : followedUsers) {
|
||||||
|
UserFollow userFollow = new UserFollow();
|
||||||
|
userFollow.setId(followedUser.getId());
|
||||||
|
userFollow.setIsFollow(true);
|
||||||
|
userFollow.setRealName(followedUser.getRealname());
|
||||||
|
userFollow.setAvatar(followedUser.getAvatar());
|
||||||
|
userFollows.add(userFollow);
|
||||||
|
}
|
||||||
|
return Result.OK(userFollows);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return Result.OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,4 +77,10 @@ public class AiolActivitySignup implements Serializable {
|
|||||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||||
@Schema(description = "更新日期")
|
@Schema(description = "更新日期")
|
||||||
private java.util.Date updateTime;
|
private java.util.Date updateTime;
|
||||||
|
/**活动id*/
|
||||||
|
@Schema(description = "活动id")
|
||||||
|
private java.lang.String activityId;
|
||||||
|
/**用户id*/
|
||||||
|
@Schema(description = "用户id")
|
||||||
|
private java.lang.String userId;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user