基于javaweb+mysql的springboot校友交流平台校园论坛(java+springboot+vue+maven+mysql+redis)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SpringBoot校友交流平台校园论坛(java+springboot+vue+maven+mysql+redis)
后台管理员:
100000000@qq.com 123456
前台用户(注册):
200000001@qq.com 123456
200000002@qq.com 123456
一、项目简述
用户角色:管理员、用户
功能介绍:
登录、公告管理、轮播图管理、地区管理、学院管理、组织管理、标签管理、用户管理、内推管理、帖子管理、添加帖子、帖子信息、问题管理、动态管理、关于作者
二、项目运行
环境配置: Jdk1.8 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术: Springboot + VUE + ElementUI + maven等等。
BeanUtils.copyProperties(roleAddRequest, role);
Boolean isSuccess = roleService.addRole(role);
return ResultUtils.success(isSuccess);
}
@PostMapping("/updateRole")
public BaseResponse<Boolean> updateRole(@RequestBody RoleUpdateRequest roleUpdateRequest) {
if (roleUpdateRequest.getId() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(roleUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isBlank(roleUpdateRequest.getRoleName()) ||
StringUtils.isBlank(roleUpdateRequest.getRoleValue())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(roleUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Role role = new Role();
BeanUtils.copyProperties(roleUpdateRequest, role);
Boolean isSuccess = roleService.updateRole(role);
return ResultUtils.success(isSuccess);
}
@DeleteMapping("/deleteRole")
public BaseResponse<Boolean> deleteRole(@RequestBody RoleDeleteRequest roleDeleteRequest) {
roleDeleteRequest.getIds().forEach(id -> {
if (id < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(id));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
});
Boolean isSuccess = roleService.deleteRole(roleDeleteRequest.getIds());
return ResultUtils.success(isSuccess);
}
@PostMapping("/getRoleByPage")
public BaseResponse<Map<String, Object>> getRoleByPage(@RequestBody GetRoleByPageRequest getRoleByPageRequest) {
if (getRoleByPageRequest.getPageNum() < CommonConstant.MIN_PAGE_NUM ||
getRoleByPageRequest.getPageSize() < CommonConstant.MIN_PAGE_SIZE) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(getRoleByPageRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
GetRoleByPageQuery getRoleByPageQuery = new GetRoleByPageQuery();
BeanUtils.copyProperties(getRoleByPageRequest, getRoleByPageQuery);
Map<String, Object> map = roleService.getRoleByPage(getRoleByPageQuery);
return ResultUtils.success(map);
}
@PostMapping("/addRoleToUser")
public BaseResponse<Boolean> addRoleToUser(@RequestBody RoleAddToUserRequest roleAddToUserRequest) {
if (roleAddToUserRequest.getRoleId() < CommonConstant.MIN_ID ||
roleAddToUserRequest.getUserId() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(roleAddToUserRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
});
Boolean isSuccess = questionService.deleteQuestion(questionDeleteRequest.getIds());
return ResultUtils.success(isSuccess);
}
/**
* 分页查询问题
*/
@PostMapping("/getQuestionByPage")
public BaseResponse<Map<String, Object>> getQuestionByPage(@RequestBody GetQuestionByPageRequest getQuestionByPageRequest) {
if (getQuestionByPageRequest.getPageNum() < CommonConstant.MIN_PAGE_NUM ||
getQuestionByPageRequest.getPageSize() < CommonConstant.MIN_PAGE_SIZE) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(getQuestionByPageRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
GetQuestionByPageQuery workPageQuery = new GetQuestionByPageQuery();
BeanUtils.copyProperties(getQuestionByPageRequest, workPageQuery);
Map<String, Object> map = questionService.getQuestionByPage(workPageQuery);
return ResultUtils.success(map);
}
/**
* 根据id查询问题
*/
@GetMapping("/getQuestionInfoById/{id}")
public BaseResponse<QuestionVO> getQuestionInfoById(@PathVariable Long id) {
if (id == null || id < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(id));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
QuestionVO questionInfoById = questionService.getQuestionInfoById(id);
return ResultUtils.success(questionInfoById);
}
}
}
Notice notice = new Notice();
BeanUtils.copyProperties(noticeUpdateRequest, notice);
Boolean isSuccess = noticeService.updateNotice(notice);
return ResultUtils.success(isSuccess);
}
/**
* 删除公告
*/
@DeleteMapping("/deleteNotice")
public BaseResponse<Boolean> deleteNotice(@RequestBody NoticeDeleteRequest noticeDeleteRequest) {
noticeDeleteRequest.getIds().forEach(id -> {
if (id < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(id));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
});
Boolean isSuccess = noticeService.deleteNotice(noticeDeleteRequest.getIds());
return ResultUtils.success(isSuccess);
}
/**
* 分页查看公告
*/
@PostMapping("/getNoticeByPage")
public BaseResponse<Map<String, Object>> getNoticeByPage(@RequestBody GetNoticeByPageRequest getNoticeByPageRequest) {
if (getNoticeByPageRequest.getPageNum() < CommonConstant.MIN_PAGE_NUM ||
getNoticeByPageRequest.getPageSize() < CommonConstant.MIN_PAGE_SIZE) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(getNoticeByPageRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
GetNoticeByPageQuery getNoticeByPageQuery = new GetNoticeByPageQuery();
BeanUtils.copyProperties(getNoticeByPageRequest, getNoticeByPageQuery);
Map<String, Object> map = noticeService.getNoticeByPage(getNoticeByPageQuery);
return ResultUtils.success(map);
}
}
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if ((replyUpdateNumRequest.getUid() == null)) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(replyUpdateNumRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Reply reply = new Reply();
BeanUtils.copyProperties(replyUpdateNumRequest, reply);
boolean isSuccess = replyService.updateUpNum(reply);
return ResultUtils.success(isSuccess);
}
/**
* 删除回复
*/
@DeleteMapping("/deleteReply")
public BaseResponse<Boolean> deleteReply(@RequestBody ReplyDeleteRequest replyDeleteRequest) {
replyDeleteRequest.getIds().forEach(id -> {
if (id < CommonConstant.MIN_ID) {
log.error("参数校验失败,该id为:{}", GsonUtil.toJson(id));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
});
boolean isSuccess = replyService.deleteReply(replyDeleteRequest.getIds());
return ResultUtils.success(isSuccess);
}
}
/**
* @Auther: gali
permissionDeleteRequest.getIds().forEach(id -> {
if (id < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(id));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
});
Boolean isSuccess = permissionService.deletePermission(permissionDeleteRequest.getIds());
return ResultUtils.success(isSuccess);
}
@GetMapping("/getPermissionByTree")
public BaseResponse<List<PermissionVO>> getPermissionByTree() {
List<PermissionVO> list = permissionService.getPermissionByTree();
return ResultUtils.success(list);
}
@PostMapping("/addPermissionToRole")
public BaseResponse<Boolean> addPermissionToRole(@RequestBody PermissionAddToRoleRequest permissionAddToRoleRequest) {
if (permissionAddToRoleRequest.getRoleId() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(permissionAddToRoleRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (CollectionUtils.isEmpty(permissionAddToRoleRequest.getPermissionId())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(permissionAddToRoleRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
PermissionAddToRoleQuery permissionAddToRoleQuery = new PermissionAddToRoleQuery();
BeanUtils.copyProperties(permissionAddToRoleRequest, permissionAddToRoleQuery);
permissionService.addPermissionToRole(permissionAddToRoleQuery);
return ResultUtils.success(Boolean.TRUE);
}
@GetMapping("/getRolePermissionInRoleId/{roleId}")
public BaseResponse<RolePermissionVO> getRolePermissionInRoleId(@PathVariable Long roleId) {
if (roleId < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(roleId));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
RolePermissionVO rolePermissionVO = permissionService.getRolePermissionInRoleId(roleId);
return ResultUtils.success(rolePermissionVO);
}
}
/**
* @Auther: gali
* @Description:
*/
@RestController
@RequestMapping("/role")
@Slf4j
public class RoleController {
@Resource
private RoleService roleService;
@PostMapping("/addRole")
public BaseResponse<Boolean> addRole(@RequestBody RoleAddRequest roleAddRequest) {
if (StringUtils.isBlank(roleAddRequest.getRoleName()) ||
StringUtils.isBlank(roleAddRequest.getRoleValue())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(roleAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Role role = new Role();
BeanUtils.copyProperties(roleAddRequest, role);
Boolean isSuccess = roleService.addRole(role);
return ResultUtils.success(isSuccess);
}
@PostMapping("/updateRole")
public BaseResponse<Boolean> updateRole(@RequestBody RoleUpdateRequest roleUpdateRequest) {
if (roleUpdateRequest.getId() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(roleUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
/**
* @Auther: gali
* @Description:
*/
@RestController
@RequestMapping("/discuss")
@Slf4j
public class DiscussController {
@Resource
private DiscussService discussService;
/**
* 增加讨论
*/
@PostMapping("/addDiscuss")
public BaseResponse<Boolean> addDiscuss(@RequestBody DiscussAddRequest discussAddRequest) {
if (discussAddRequest.getUid() < CommonConstant.MIN_ID ||
discussAddRequest.getTid() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isBlank(discussAddRequest.getTitle()) ||
StringUtils.isBlank(discussAddRequest.getCover()) ||
StringUtils.isBlank(discussAddRequest.getMessage())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (discussAddRequest.getTitle().length() > CommonConstant.TITLE_MAX_LENGTH ||
discussAddRequest.getMessage().length() < CommonConstant.CONTENT_MIN_LENGTH) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Discuss discuss = new Discuss();
BeanUtils.copyProperties(discussAddRequest, discuss);
boolean isSuccess = discussService.addDiscuss(discuss);
return ResultUtils.success(isSuccess);
}
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(dynamicUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if ((dynamicUpdateRequest.getUid() == null)) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(dynamicUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Dynamic dynamic = new Dynamic();
BeanUtils.copyProperties(dynamicUpdateRequest, dynamic);
Boolean isSuccess = dynamicService.updateByUp(dynamic);
return ResultUtils.success(isSuccess);
}
/**
* 修改动态信息
*/
@PostMapping("/updateDynamic")
public BaseResponse<Boolean> updateDynamic(@RequestBody DynamicUpdateRequest dynamicUpdateRequest) {
if (dynamicUpdateRequest.getId() < CommonConstant.MIN_ID ||
dynamicUpdateRequest.getUid() < CommonConstant.MIN_ID ||
dynamicUpdateRequest.getTid() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(dynamicUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isBlank(dynamicUpdateRequest.getContent())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(dynamicUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Dynamic dynamic = new Dynamic();
BeanUtils.copyProperties(dynamicUpdateRequest, dynamic);
Boolean isSuccess = dynamicService.updateDynamic(dynamic);
return ResultUtils.success(isSuccess);
}
/**
* 删除动态
*/
@DeleteMapping("/deleteDynamic")
public BaseResponse<Boolean> deleteDynamic(@RequestBody DynamicDeleteRequest dynamicDeleteRequest) {
dynamicDeleteRequest.getIds().forEach(id -> {
if (id < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(id));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
});
Boolean isSuccess = dynamicService.deleteDynamic(dynamicDeleteRequest.getIds());
return ResultUtils.success(isSuccess);
}
/**
* 分页查询动态
/**
* 用户接口
*
*/
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
@Resource
private UserService userService;
@PostMapping("/register")
public BaseResponse<Boolean> userRegister(@RequestBody UserRegisterRequest userRegisterRequest) {
if (userRegisterRequest.getCollegeId() < CommonConstant.MIN_ID ||
userRegisterRequest.getRid() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(userRegisterRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isBlank(userRegisterRequest.getEmail()) ||
StringUtils.isBlank(userRegisterRequest.getPassword()) ||
StringUtils.isBlank(userRegisterRequest.getCode())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(userRegisterRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (userRegisterRequest.getPassword().length() < 1) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(userRegisterRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR, "用户密码过短");
}
User user = new User();
BeanUtils.copyProperties(userRegisterRequest, user);
user.setPasssword(userRegisterRequest.getPassword());
Boolean isSuccess = userService.userRegister(user, userRegisterRequest.getCode());
return ResultUtils.success(isSuccess);
}
@GetMapping("/getEmailCode")
public BaseResponse<String> getEmailCode(@RequestParam String email) {
userService.getEmailCode(email);
return ResultUtils.success("success");
}
@PostMapping("/login")
public BaseResponse<String> userLogin(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request) {
if (StringUtils.isBlank(userLoginRequest.getEmail()) ||
return ResultUtils.success(isSuccess);
}
/**
* 更新讨论
*/
@PostMapping("/updateDiscuss")
public BaseResponse<Boolean> updateDiscuss(@RequestBody DiscussUpdateRequest discussUpdateRequest) {
if (discussUpdateRequest.getUid() < CommonConstant.MIN_ID ||
discussUpdateRequest.getId() < CommonConstant.MIN_ID ||
discussUpdateRequest.getTid() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isBlank(discussUpdateRequest.getTitle()) ||
StringUtils.isBlank(discussUpdateRequest.getCover()) ||
StringUtils.isBlank(discussUpdateRequest.getMessage())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (discussUpdateRequest.getIsAudit() < AuditEnum.AUDITING.getType() ||
discussUpdateRequest.getIsAudit() > AuditEnum.AUDIT_REFUSE.getType()) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Discuss discuss = new Discuss();
BeanUtils.copyProperties(discussUpdateRequest, discuss);
boolean isSuccess = discussService.updateDiscuss(discuss);
return ResultUtils.success(isSuccess);
}
/**
* 删除讨论
*/
@DeleteMapping("/deleteDiscuss")
public BaseResponse<Boolean> deleteDiscuss(@RequestBody DiscussDeleteRequest discussDeleteRequest) {
discussDeleteRequest.getIds().forEach(item -> {
if (item < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(item));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
});
boolean isSuccess = discussService.deleteDiscuss(discussDeleteRequest.getIds());
return ResultUtils.success(isSuccess);
}
/**
* 点赞相关
*/
@PostMapping("/upOrDownAction")
public BaseResponse<Boolean> upOrDownAction(@RequestBody DiscussUpOrDownRequest discussUpOrDownRequest) {
if (discussUpOrDownRequest.getId() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussUpOrDownRequest));
/**
* @Auther: gali
* @Description:
*/
@RestController
@RequestMapping("/question")
@Slf4j
public class QuestionController {
@Resource
private QuestionService questionService;
/**
* 添加问题
*/
@PostMapping("/addQuestion")
public BaseResponse<Boolean> addQuestion(@RequestBody QuestionAddRequest questionAddRequest) {
if (questionAddRequest.getUid() == null || questionAddRequest.getTid() == null) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(questionAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isBlank(questionAddRequest.getTitle()) || StringUtils.isBlank(questionAddRequest.getContent())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(questionAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (questionAddRequest.getTitle().length() > CommonConstant.TITLE_MAX_LENGTH ||
questionAddRequest.getContent().length() < CommonConstant.CONTENT_MIN_LENGTH) {
System.out.println(questionAddRequest.getTitle().length() > CommonConstant.TITLE_MAX_LENGTH);
System.out.println(questionAddRequest.getContent().length() < CommonConstant.CONTENT_MIN_LENGTH);
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(questionAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Question question = new Question();
BeanUtils.copyProperties(questionAddRequest, question);
Boolean isSuccess = questionService.addQuestion(question);
return ResultUtils.success(isSuccess);
}
/**
* 更新问题及审核
*/
@PostMapping("/updateQuestion")
public BaseResponse<Boolean> updateQuestion(@RequestBody QuestionUpdateRequest questionUpdateRequest) {
if (questionUpdateRequest.getId() < CommonConstant.MIN_ID ||
questionUpdateRequest.getTid() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(questionUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
/**
* @Auther: gali
* @Description:
*/
@RestController
@RequestMapping("/dynamic")
@Slf4j
public class DynamicController {
@Resource
private DynamicService dynamicService;
/**
* 添加动态
*/
@PostMapping("/addDynamic")
public BaseResponse<Boolean> addDynamic(@RequestBody DynamicAddRequest dynamicAddRequest) {
if (dynamicAddRequest.getUid() < CommonConstant.MIN_ID ||
dynamicAddRequest.getTid() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(dynamicAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isBlank(dynamicAddRequest.getContent())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(dynamicAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Dynamic dynamic = new Dynamic();
BeanUtils.copyProperties(dynamicAddRequest, dynamic);
Boolean isSuccess = dynamicService.addDynamic(dynamic);
return ResultUtils.success(isSuccess);
}
/**
* 更改点赞
*/
@PostMapping("/updateByUp")
public BaseResponse<Boolean> updateByUp(@RequestBody DynamicUpdateRequest dynamicUpdateRequest) {
if (dynamicUpdateRequest.getId() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(dynamicUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if ((dynamicUpdateRequest.getUid() == null)) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(dynamicUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Dynamic dynamic = new Dynamic();
BeanUtils.copyProperties(dynamicUpdateRequest, dynamic);
Boolean isSuccess = dynamicService.updateByUp(dynamic);
return ResultUtils.success(isSuccess);
}
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(userRegisterRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (userRegisterRequest.getPassword().length() < 1) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(userRegisterRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR, "用户密码过短");
}
User user = new User();
BeanUtils.copyProperties(userRegisterRequest, user);
user.setPasssword(userRegisterRequest.getPassword());
Boolean isSuccess = userService.userRegister(user, userRegisterRequest.getCode());
return ResultUtils.success(isSuccess);
}
@GetMapping("/getEmailCode")
public BaseResponse<String> getEmailCode(@RequestParam String email) {
userService.getEmailCode(email);
return ResultUtils.success("success");
}
@PostMapping("/login")
public BaseResponse<String> userLogin(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request) {
if (StringUtils.isBlank(userLoginRequest.getEmail()) ||
StringUtils.isBlank(userLoginRequest.getPassword())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(userLoginRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
User user = new User();
user.setPasssword(userLoginRequest.getPassword());
BeanUtils.copyProperties(userLoginRequest, user);
String token = userService.userLogin(user, request);
return ResultUtils.success(token);
}
@PostMapping("/adminLogin")
public BaseResponse<String> adminLogin(@RequestBody UserLoginRequest userLoginRequest) {
if (StringUtils.isBlank(userLoginRequest.getEmail()) ||
StringUtils.isBlank(userLoginRequest.getPassword())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(userLoginRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
User user = new User();
BeanUtils.copyProperties(userLoginRequest, user);
Boolean isSuccess = noticeService.updateNotice(notice);
return ResultUtils.success(isSuccess);
}
/**
* 删除公告
*/
@DeleteMapping("/deleteNotice")
public BaseResponse<Boolean> deleteNotice(@RequestBody NoticeDeleteRequest noticeDeleteRequest) {
noticeDeleteRequest.getIds().forEach(id -> {
if (id < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(id));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
});
Boolean isSuccess = noticeService.deleteNotice(noticeDeleteRequest.getIds());
return ResultUtils.success(isSuccess);
}
/**
* 分页查看公告
*/
@PostMapping("/getNoticeByPage")
public BaseResponse<Map<String, Object>> getNoticeByPage(@RequestBody GetNoticeByPageRequest getNoticeByPageRequest) {
if (getNoticeByPageRequest.getPageNum() < CommonConstant.MIN_PAGE_NUM ||
getNoticeByPageRequest.getPageSize() < CommonConstant.MIN_PAGE_SIZE) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(getNoticeByPageRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
GetNoticeByPageQuery getNoticeByPageQuery = new GetNoticeByPageQuery();
BeanUtils.copyProperties(getNoticeByPageRequest, getNoticeByPageQuery);
Map<String, Object> map = noticeService.getNoticeByPage(getNoticeByPageQuery);
return ResultUtils.success(map);
}
}
log.error("参数校验失败,删除id为:{}", GsonUtil.toJson(id));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
});
DeleteOriginQuery deleteOriginQuery = new DeleteOriginQuery();
BeanUtils.copyProperties(originDeleteRequest, deleteOriginQuery);
Boolean flag = originService.deleteOrigin(deleteOriginQuery);
return ResultUtils.success(flag);
}
/**
* 条件分页获取组织
*/
@PostMapping("/GetOriginByQueryAndPage")
public BaseResponse<Map<String, Object>> GetOriginByQueryAndPage(@RequestBody GetOriginRequest getOriginRequest) {
boolean isErrorParam = getOriginRequest.getPageNum() < CommonConstant.MIN_PAGE_NUM ||
getOriginRequest.getPageSize() < CommonConstant.MIN_PAGE_SIZE;
if (isErrorParam) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(getOriginRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
GetOriginQuery getOriginQuery = new GetOriginQuery();
BeanUtils.copyProperties(getOriginRequest, getOriginQuery);
Map<String, Object> originVOS = originService.GetOriginByQueryAndPage(getOriginQuery);
return ResultUtils.success(originVOS);
}
}
@PostMapping("/logout")
public BaseResponse<Integer> userLogout(HttpServletRequest request) {
int i = userService.userLogout(request);
return ResultUtils.success(i);
}
@GetMapping("/current")
public BaseResponse<UserVO> getCurrentUser(@RequestParam String token) {
if (StringUtils.isBlank(token)) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(token));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
UserVO user = userService.getCurrentUser(token);
return ResultUtils.success(user);
}
@PostMapping("/updateUser")
public BaseResponse<Boolean> updateUser(@RequestBody UserUpdateRequest userUpdateRequest) {
if (userUpdateRequest.getUser() == null ||
userUpdateRequest.getUserInfo() == null) {
log.error("参数校验失败,用户基本信息为:{},详细信息为:{}", GsonUtil.toJson(userUpdateRequest.getUser()),
GsonUtil.toJson(userUpdateRequest.getUserInfo()));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (userUpdateRequest.getUser().getUsername() != null && userUpdateRequest.getUser().getUsername().length() > CommonConstant.MAX_USERNAME_LENGTH) {
log.error("参数校验失败,用户基本信息为:{},详细信息为:{}", GsonUtil.toJson(userUpdateRequest.getUser()),
GsonUtil.toJson(userUpdateRequest.getUserInfo()));
throw new BusinessException(ErrorCode.PARAMS_ERROR, "用户名长度不能超过20");
}
User user = new User();
UserInfo userInfo = new UserInfo();
BeanUtils.copyProperties(userUpdateRequest.getUser(), user);
BeanUtils.copyProperties(userUpdateRequest.getUserInfo(), userInfo);
Boolean isSuccess = userService.updateUser(user, userInfo);
return ResultUtils.success(isSuccess);
}
@PostMapping("/getUserByPage")
public BaseResponse<Map<String, Object>> getUserByPage(@RequestBody GetUserByPageRequest getUserByPageRequest) {
if (getUserByPageRequest.getPageNum() < CommonConstant.MIN_PAGE_NUM ||
getUserByPageRequest.getPageSize() < CommonConstant.MIN_PAGE_SIZE) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(getUserByPageRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isBlank(discussAddRequest.getTitle()) ||
StringUtils.isBlank(discussAddRequest.getCover()) ||
StringUtils.isBlank(discussAddRequest.getMessage())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (discussAddRequest.getTitle().length() > CommonConstant.TITLE_MAX_LENGTH ||
discussAddRequest.getMessage().length() < CommonConstant.CONTENT_MIN_LENGTH) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussAddRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Discuss discuss = new Discuss();
BeanUtils.copyProperties(discussAddRequest, discuss);
boolean isSuccess = discussService.addDiscuss(discuss);
return ResultUtils.success(isSuccess);
}
/**
* 更新讨论
*/
@PostMapping("/updateDiscuss")
public BaseResponse<Boolean> updateDiscuss(@RequestBody DiscussUpdateRequest discussUpdateRequest) {
if (discussUpdateRequest.getUid() < CommonConstant.MIN_ID ||
discussUpdateRequest.getId() < CommonConstant.MIN_ID ||
discussUpdateRequest.getTid() < CommonConstant.MIN_ID) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isBlank(discussUpdateRequest.getTitle()) ||
StringUtils.isBlank(discussUpdateRequest.getCover()) ||
StringUtils.isBlank(discussUpdateRequest.getMessage())) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (discussUpdateRequest.getIsAudit() < AuditEnum.AUDITING.getType() ||
discussUpdateRequest.getIsAudit() > AuditEnum.AUDIT_REFUSE.getType()) {
log.error("参数校验失败,该参数为:{}", GsonUtil.toJson(discussUpdateRequest));
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Discuss discuss = new Discuss();