package com.example.springboot.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Quarter;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot.config.interceptor.AuthAccess;
import com.example.springboot.controller.dto.UserDTO;
import com.example.springboot.controller.dto.UserPasswordDTO;
import com.example.springboot.entity.Dormitory;
import com.example.springboot.entity.User;
import com.example.springboot.exception.ServiceException;
import com.example.springboot.service.IArriveschoolService;
import com.example.springboot.service.IDormitoryService;
import com.example.springboot.service.IUserService;
import com.example.springboot.common.Constants;
import com.example.springboot.common.Result;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author
* @since 2022-01-26
*/
@RestController
@RequestMapping("/user")
public class UserController {
@Resource
private IUserService userService;
@Resource
private IArriveschoolService arriveschoolService;
@Resource
private IDormitoryService dormitoryService;
@PostMapping("/login")
public Result login(@RequestBody UserDTO userDTO) {
String username = userDTO.getUsername();
String password = userDTO.getPassword();
if (StrUtil.isBlank(username) || StrUtil.isBlank(password)) {
return Result.error(Constants.CODE_400, "参数错误");
}
UserDTO dto = userService.login(userDTO);
return Result.success(dto);
}
@PostMapping("/register")
public Result register(@RequestBody UserDTO userDTO) {
String username = userDTO.getUsername();
String password = userDTO.getPassword();
if (StrUtil.isBlank(username) || StrUtil.isBlank(password)) {
return Result.error(Constants.CODE_400, "参数错误");
}
userDTO.setNickname(userDTO.getUsername());
return Result.success(userService.register(userDTO));
}
// 新增或者更新
@PostMapping
public Result save(@RequestBody User user) {
String username = user.getUsername();
if (StrUtil.isBlank(username)) {
return Result.error(Constants.CODE_400, "参数错误");
}
if (StrUtil.isBlank(user.getNickname())) {
user.setNickname(username);
}
if (user.getId() != null) {
user.setPassword(null);
} else {
if (user.getPassword() == null) {
user.setPassword("123");
}
}
// Integer dormid = user.getDormid();
// Dormitory byId = dormitoryService.getById(dormid);
// if(null != byId){
// user.setDormaddress(byId.getAddress());
// int total = byId.getExisttotal() + 1;
// if(total > byId.getTotal()){
// return Result.error("400","该宿舍已经住满,不能增加住宿");
// }
// byId.setExisttotal(byId.getExisttotal() + 1);
// dormitoryService.updateById(byId);
// }
return Result.success(userService.saveOrUpdate(user));
}
// 新增或者更新
@PostMapping("/saveDorm")
public Result saveDorm(@RequestBody User user) {
Integer dormid = user.getDormid();
Dormitory byId = dormitoryService.getById(dormid);
if(null != byId){
user.setDormaddress(byId.getAddress());
int total = byId.getExisttotal() + 1;
if(total > byId.getTotal()){
return Result.error("400","该宿舍已经住满,不能增加住宿");
}
byId.setExisttotal(byId.getExisttotal() + 1);
dormitoryService.updateById(byId);
}
return Result.success(userService.saveOrUpdate(user));
}
/**
* 修改密码
*
* @param userPasswordDTO
* @return
*/
@PostMapping("/password")
public Result password(@RequestBody UserPasswordDTO userPasswordDTO) {
userService.updatePassword(userPasswordDTO);
return Result.success();
}
@AuthAccess
@PutMapping("/reset")
public Result reset(@RequestBody UserPasswordDTO userPasswordDTO) {
if (StrUtil.isBlank(userPasswordDTO.getUsername()) || StrUtil.isBlank(userPasswordDTO.getPhone())) {
throw new ServiceException("-1", "参数异常");
}
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("username", userPasswordDTO.getUsername());
queryWrapper.eq("phone", userPasswordDTO.getPhone());
List<User> list = userService.list(queryWrapper);
if (CollUtil.isNotEmpty(list)) {
User user = list.get(0);
user.setPassword("123");
userService.updateById(user);
} else {
return Result.error("-1", "未找到用户");
}
return Result.success();
}
@DeleteMapping("/{id}")
public Result delete(@PathVariable Integer id) {
return Result.success(userService.removeById(id));
}
@PostMapping("/unDorm/{id}")
public Result unDorm(@PathVariable Integer id) {
User user = userService.getById(id);
String isdorm = user.getIsdorm();
if("未住宿".equals(isdorm)){
return Result.error("400","未分配住宿,不能取消住宿");
}
Integer dormid = user.getDormid();
Dormitory byId = dormitoryService.getById(dormid);
byId.setExisttotal(byId.getExisttotal() - 1);
dormitoryService.updateById(byId);
user.setDormaddress("");
user.setIsdorm("未住宿");
user.setDormid(null);
userService.updateDormIdNull(user.getId());
return Result.success(userService.updateById(user));
}
@PostMapping("/del/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
return Result.success(userService.removeByIds(ids));
}
@GetMapping
public Result findAll() {
return Result.success(userService.list());
}
@GetMapping("/{id}")
public Result findOne(@PathVariable Integer id) {
return Result.success(userService.getById(id));
}
@GetMapping("/username/{username}")
public Result findByUsername(@PathVariable String username) {
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("username", username);
return Result.success(userService.getOne(queryWrapper));
}
@GetMapping("/page")
public Result findPage(@RequestParam Integer pageNum,
@RequestParam Integer pageSize,
@RequestParam(defaultValue = "") String username,
@RequestParam(defaultValue = "") String role,
@RequestParam(defaultValue = "") String email,
@RequestParam(defaultValue = "") String address) {
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.orderByDesc("id");
if (!"".equals(username)) {
queryWrapper.like("username", username);
}
i
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
《新生报到网站》是一个基于Vue.js和SpringBoot的前后端分离新手入门项目,旨在为新生提供一个便捷的报到平台。该项目包含管理后台和用户网站两个部分,功能丰富,涵盖了在线交流、宿舍分配、校园概况、专业管理、宿舍报修等多个模块。在线交流模块允许新生和在校生进行实时沟通,分享经验和建议;宿舍分配模块则根据新生的性别、专业等信息,智能分配宿舍;校园概况模块详细介绍了学校的地理位置、校园环境、设施资源等信息,帮助新生更好地了解学校;专业管理模块则为新生提供了专业选择和课程安排的参考;宿舍报修模块则方便新生在遇到宿舍问题时,能够及时报修并得到解决。整个项目采用现代化的前后端分离架构,易于扩展和维护,是新手入门学习Vue.js和SpringBoot技术的绝佳实践项目。 录屏:https://www.bilibili.com/video/BV1Rw411878S 教程:https://space.bilibili.com/417412814/channel/collectiondetail?sid=2242844
资源推荐
资源详情
资源评论
收起资源包目录
基于springboot的新生报到网站 源码+数据库(毕业设计) (152个子文件)
gloable.css 268B
index.html 588B
favicon.ico 4KB
UserController.java 16KB
FileController.java 8KB
ArriveschoolController.java 6KB
DormrepairController.java 6KB
DormitoryController.java 5KB
CommentController.java 5KB
SchoolintroduceController.java 5KB
UserServiceImpl.java 5KB
SubjectController.java 4KB
ClassesController.java 4KB
MenuController.java 3KB
JwtInterceptor.java 3KB
RoleServiceImpl.java 2KB
RoleController.java 2KB
TokenUtils.java 2KB
User.java 2KB
EchartsController.java 2KB
IpUtils.java 2KB
MenuServiceImpl.java 1KB
SwaggerConfig.java 1KB
InterceptorConfig.java 1KB
Comment.java 1KB
Schoolintroduce.java 1KB
Dormrepair.java 1KB
Arriveschool.java 1KB
Menu.java 1KB
Subject.java 1KB
CorsConfig.java 1KB
Dormitory.java 961B
Role.java 899B
MybatisPlusConfig.java 815B
Classes.java 806B
Result.java 780B
UserMapper.java 742B
GlobalExceptionHandler.java 673B
RoleMenuMapper.java 654B
IUserService.java 588B
SchoolintroduceServiceImpl.java 548B
Files.java 530B
ArriveschoolServiceImpl.java 527B
DormitoryServiceImpl.java 525B
DormrepairServiceImpl.java 513B
SubjectServiceImpl.java 501B
ClassesServiceImpl.java 492B
CommentServiceImpl.java 489B
RoleMapper.java 477B
UserDTO.java 455B
IRoleService.java 408B
IMenuService.java 357B
Constants.java 349B
SpringbootApplication.java 335B
ServiceException.java 311B
IDormitoryService.java 291B
DormitoryMapper.java 290B
ISchoolintroduceService.java 290B
SchoolintroduceMapper.java 289B
IArriveschoolService.java 281B
ArriveschoolMapper.java 280B
ISubjectService.java 275B
IDormrepairService.java 275B
MenuMapper.java 274B
SubjectMapper.java 274B
DormrepairMapper.java 274B
IClassesService.java 266B
ClassesMapper.java 265B
ICommentService.java 263B
CommentMapper.java 262B
Dict.java 258B
RoleMenu.java 246B
UserPasswordDTO.java 235B
SpringbootApplicationTests.java 227B
FileMapper.java 206B
DictMapper.java 204B
AuthAccess.java 202B
TableColumn.java 150B
RoleEnum.java 97B
2f665e18ae6b42b69331e6a878c4c496.jpg 210KB
test.jpg 31KB
test1.jpg 29KB
index.js 4KB
request.js 2KB
index.js 608B
main.js 454B
vue.config.js 95B
babel.config.js 73B
package-lock.json 713KB
package.json 634B
404.png 95KB
login.png 45KB
logo1.png 22KB
register.png 18KB
logo.png 15KB
logo.png 12KB
t002.sql 32KB
vue.template 7KB
controller.java.vm 5KB
entity.java.vm 4KB
共 152 条
- 1
- 2
资源评论
customer08
- 粉丝: 5243
- 资源: 551
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功