From b31ef51f627536838d5bf549675bef8541b56df1 Mon Sep 17 00:00:00 2001
From: GitHub <2041376447@qq.com>
Date: Thu, 26 Dec 2024 11:31:01 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E5=90=8E=E7=AB=AF?=
=?UTF-8?q?=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 47 +++++++++++++
ruoyi-system/pom.xml | 5 ++
.../controller/DormitoryAdminController.java | 41 +++++++++++-
.../controller/DormitoryController.java | 12 ++++
.../system/controller/StudentController.java | 43 ++++++++++--
.../java/com/ruoyi/system/domain/Student.java | 12 ++--
.../system/mapper/DormitoryAdminMapper.java | 23 ++++++-
.../ruoyi/system/mapper/DormitoryMapper.java | 3 +
.../ruoyi/system/mapper/StudentMapper.java | 10 +++
.../service/IDormitoryAdminService.java | 9 ++-
.../system/service/IDormitoryService.java | 2 +
.../ruoyi/system/service/IStudentService.java | 6 ++
.../impl/DormitoryAdminServiceImpl.java | 67 ++++++++++++++++++-
.../service/impl/DormitoryServiceImpl.java | 4 ++
.../service/impl/StudentServiceImpl.java | 37 ++++++++++
.../main/java/com/ruoyi/system/vo/PageVo.java | 10 ---
.../mapper/system/DormitoryAdminMapper.xml | 17 ++++-
.../resources/mapper/system/StudentMapper.xml | 10 ++-
18 files changed, 327 insertions(+), 31 deletions(-)
create mode 100644 .gitignore
delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/vo/PageVo.java
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ed8368a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,47 @@
+######################################################################
+# Build Tools
+
+.gradle
+/build/
+!gradle/wrapper/gradle-wrapper.jar
+
+target/
+!.mvn/wrapper/maven-wrapper.jar
+
+######################################################################
+# IDE
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### JRebel ###
+rebel.xml
+
+### NetBeans ###
+nbproject/private/
+build/*
+nbbuild/
+dist/
+nbdist/
+.nb-gradle/
+
+######################################################################
+# Others
+*.log
+*.xml.versionsBackup
+*.swp
+
+!*/build/*.java
+!*/build/*.html
+!*/build/*.xml
diff --git a/ruoyi-system/pom.xml b/ruoyi-system/pom.xml
index 3455bc5..5a05be5 100644
--- a/ruoyi-system/pom.xml
+++ b/ruoyi-system/pom.xml
@@ -49,6 +49,11 @@
org.springframework.boot
spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
\ No newline at end of file
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryAdminController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryAdminController.java
index 5162d24..a386b9c 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryAdminController.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryAdminController.java
@@ -1,11 +1,18 @@
package com.ruoyi.system.controller;
+import java.security.Key;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.system.form.RuleForm;
+import com.ruoyi.system.form.SearchForm;
+import com.ruoyi.system.vo.PageResult;
import com.ruoyi.system.vo.ResultVo;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -38,6 +45,32 @@ public class DormitoryAdminController extends BaseController
ResultVo resultVo = this.dormitoryAdminService.login(ruleForm);
return resultVo;
}
+ @Anonymous
+ @GetMapping("/list/{page}/{size}")
+ public ResponseEntity> getAllDormitoryAdmins(
+ @PathVariable("page") int page, // 使用 @PathVariable 而不是 @RequestParam
+ @PathVariable("size") int size) { // 同样使用 @PathVariable
+
+ // 注意:通常页码从 1 开始更合理,但这里保留您的默认值 0
+ // 如果业务逻辑需要页码从 1 开始,您可能需要在服务层添加额外的处理
+
+ PageResult pageResult = dormitoryAdminService.findAll(page-1, size);
+ return ResponseEntity.ok(pageResult);
+ }
+ @Anonymous
+ @GetMapping("/search")
+ public PageResult search(SearchForm searchForm){
+ return dormitoryAdminService.search(searchForm);
+ }
+ @Anonymous
+ @GetMapping("findById/{id}")
+ public ResultVo findById(@PathVariable("id") Integer id){
+ DormitoryAdmin dormitoryAdmin = this.dormitoryAdminService.selectDormitoryAdminById(id);
+ ResultVo resultVo = new ResultVo();
+ resultVo.setCode(0);
+ resultVo.setData(dormitoryAdmin);
+ return resultVo;
+ }
/**
* 查询宿舍管理员列表
*/
@@ -89,9 +122,10 @@ public class DormitoryAdminController extends BaseController
/**
* 修改宿舍管理员
*/
- @PreAuthorize("@ss.hasPermi('system:dormitoryAdmin:edit')")
+ /* @PreAuthorize("@ss.hasPermi('system:dormitoryAdmin:edit')")*/
+ @Anonymous
@Log(title = "宿舍管理员", businessType = BusinessType.UPDATE)
- @PutMapping
+ @PutMapping("/update")
public AjaxResult edit(@RequestBody DormitoryAdmin dormitoryAdmin)
{
return toAjax(dormitoryAdminService.updateDormitoryAdmin(dormitoryAdmin));
@@ -100,7 +134,8 @@ public class DormitoryAdminController extends BaseController
/**
* 删除宿舍管理员
*/
- @PreAuthorize("@ss.hasPermi('system:dormitoryAdmin:remove')")
+ /* @PreAuthorize("@ss.hasPermi('system:dormitoryAdmin:remove')")*/
+ @Anonymous
@Log(title = "宿舍管理员", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Integer[] ids)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryController.java
index bda194c..c11cce1 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryController.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/DormitoryController.java
@@ -2,6 +2,10 @@ package com.ruoyi.system.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.common.annotation.Anonymous;
+import com.ruoyi.system.vo.ResultVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -34,6 +38,14 @@ public class DormitoryController extends BaseController
@Autowired
private IDormitoryService dormitoryService;
+ @Anonymous
+ @GetMapping("/available")
+ public ResultVo availableList(){
+ List list = dormitoryService.getAvailableDormitories();
+ ResultVo resultVo = new ResultVo();
+ resultVo.setData(list);
+ return resultVo;
+ }
/**
* 查询宿舍表列表
*/
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/StudentController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/StudentController.java
index 092b19f..26cd8a9 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/StudentController.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/StudentController.java
@@ -2,6 +2,11 @@ package com.ruoyi.system.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.common.annotation.Anonymous;
+import com.ruoyi.system.domain.DormitoryAdmin;
+import com.ruoyi.system.vo.PageResult;
+import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -34,10 +39,31 @@ public class StudentController extends BaseController
@Autowired
private IStudentService studentService;
+ @Anonymous
+ @PostMapping("/save")
+ public AjaxResult saveStudent(@RequestBody Student student)
+ {
+ Boolean saveStudent = studentService.saveStudent(student);
+ if(!saveStudent) return AjaxResult.warn("添加失败");
+ return AjaxResult.success("添加成功");
+ }
+ @Anonymous
+ @GetMapping("/list/{page}/{size}")
+ public ResponseEntity> listStudent(
+ @PathVariable("page") int page, // 使用 @PathVariable 而不是 @RequestParam
+ @PathVariable("size") int size) { // 同样使用 @PathVariable
+
+ // 注意:通常页码从 1 开始更合理,但这里保留您的默认值 0
+ // 如果业务逻辑需要页码从 1 开始,您可能需要在服务层添加额外的处理
+
+ PageResult pageResult = studentService.findAll(page-1, size);
+ return ResponseEntity.ok(pageResult);
+ }
/**
* 查询学生表列表
*/
- @PreAuthorize("@ss.hasPermi('system:student:list')")
+ @Anonymous
+ /*@PreAuthorize("@ss.hasPermi('system:student:list')")*/
@GetMapping("/list")
public TableDataInfo list(Student student)
{
@@ -49,7 +75,8 @@ public class StudentController extends BaseController
/**
* 导出学生表列表
*/
- @PreAuthorize("@ss.hasPermi('system:student:export')")
+// @PreAuthorize("@ss.hasPermi('system:student:export')")
+ @Anonymous
@Log(title = "学生表", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Student student)
@@ -62,7 +89,8 @@ public class StudentController extends BaseController
/**
* 获取学生表详细信息
*/
- @PreAuthorize("@ss.hasPermi('system:student:query')")
+// @PreAuthorize("@ss.hasPermi('system:student:query')")
+ @Anonymous
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
@@ -72,7 +100,8 @@ public class StudentController extends BaseController
/**
* 新增学生表
*/
- @PreAuthorize("@ss.hasPermi('system:student:add')")
+// @PreAuthorize("@ss.hasPermi('system:student:add')")
+ @Anonymous
@Log(title = "学生表", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody Student student)
@@ -83,7 +112,8 @@ public class StudentController extends BaseController
/**
* 修改学生表
*/
- @PreAuthorize("@ss.hasPermi('system:student:edit')")
+// @PreAuthorize("@ss.hasPermi('system:student:edit')")
+ @Anonymous
@Log(title = "学生表", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody Student student)
@@ -94,7 +124,8 @@ public class StudentController extends BaseController
/**
* 删除学生表
*/
- @PreAuthorize("@ss.hasPermi('system:student:remove')")
+// @PreAuthorize("@ss.hasPermi('system:student:remove')")
+ @Anonymous
@Log(title = "学生表", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Student.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Student.java
index 55c9273..ac3f4e6 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Student.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Student.java
@@ -32,7 +32,7 @@ public class Student extends BaseEntity
/** dormitory_id */
@Excel(name = "dormitory_id")
- private Long dormitoryId;
+ private Long dormitory_id;
/** state */
@Excel(name = "state")
@@ -40,7 +40,7 @@ public class Student extends BaseEntity
/** create_date */
@Excel(name = "create_date")
- private String createDate;
+ private String create_date;
public void setId(Long id)
{
@@ -80,12 +80,12 @@ public class Student extends BaseEntity
}
public void setDormitoryId(Long dormitoryId)
{
- this.dormitoryId = dormitoryId;
+ this.dormitory_id = dormitoryId;
}
public Long getDormitoryId()
{
- return dormitoryId;
+ return dormitory_id;
}
public void setState(String state)
{
@@ -98,12 +98,12 @@ public class Student extends BaseEntity
}
public void setCreateDate(String createDate)
{
- this.createDate = createDate;
+ this.create_date = createDate;
}
public String getCreateDate()
{
- return createDate;
+ return create_date;
}
@Override
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryAdminMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryAdminMapper.java
index 0d02a34..7fe58ad 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryAdminMapper.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryAdminMapper.java
@@ -3,6 +3,9 @@ package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.domain.DormitoryAdmin;
+import com.ruoyi.system.vo.PageResult;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
/**
* 宿舍管理员Mapper接口
@@ -13,8 +16,24 @@ import com.ruoyi.system.domain.DormitoryAdmin;
public interface DormitoryAdminMapper
{
public DormitoryAdmin selectDormitoryAdminByUsername(String username);
+ // 这是一个示例方法,用于根据分页参数查询所有DormitoryAdmin记录
+ @Select("SELECT * FROM dormitory_admin LIMIT #{offset}, #{limit}")
+ List findDormitoryAdminsByPage(@Param("offset") int offset, @Param("limit") int limit);
- /**
+ // 查询总记录数
+ @Select("SELECT COUNT(*) FROM dormitory_admin")
+ int countDormitoryAdmins();
+
+ // 这是一个自定义查询方法,用于根据名称和职位包含的条件进行分页查询
+ List findDormitoryAdminsByValueAndPage(
+ @Param("searchColumn") String searchColumn, // 注意:这里不直接传递用户输入的列名,而是传递一个经过验证的列名
+ @Param("searchValue") String searchValue,
+ @Param("offset") int offset,
+ @Param("size") int size
+ );
+ int countDormitoryAdminsByValue(@Param("searchColumn") String searchType, @Param("searchValue") String searchValue);
+
+/**
* 查询宿舍管理员
*
* @param id 宿舍管理员主键
@@ -61,4 +80,6 @@ public interface DormitoryAdminMapper
* @return 结果
*/
public int deleteDormitoryAdminByIds(Integer[] ids);
+
+
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryMapper.java
index 6a4c847..1f26231 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryMapper.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/DormitoryMapper.java
@@ -2,6 +2,7 @@ package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.domain.Dormitory;
+import org.apache.ibatis.annotations.Select;
/**
* 宿舍表Mapper接口
@@ -11,6 +12,8 @@ import com.ruoyi.system.domain.Dormitory;
*/
public interface DormitoryMapper
{
+ @Select("SELECT * FROM dormitory WHERE availabe > 0")
+ List selectAvailableDormitories();
/**
* 查询宿舍表
*
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/StudentMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/StudentMapper.java
index 346999e..2b6e28c 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/StudentMapper.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/StudentMapper.java
@@ -1,7 +1,11 @@
package com.ruoyi.system.mapper;
import java.util.List;
+
+import com.ruoyi.system.domain.DormitoryAdmin;
import com.ruoyi.system.domain.Student;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
/**
* 学生表Mapper接口
@@ -11,6 +15,12 @@ import com.ruoyi.system.domain.Student;
*/
public interface StudentMapper
{
+ /*@Select("SELECT * FROM student LIMIT #{offset}, #{limit}")*/
+ List findDormitoryAdminsByPage(@Param("offset") int offset, @Param("limit") int limit);
+
+ // 查询总记录数
+ @Select("SELECT COUNT(*) FROM student")
+ int countDormitoryAdmins();
/**
* 查询学生表
*
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryAdminService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryAdminService.java
index abaadf7..8ef58b7 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryAdminService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryAdminService.java
@@ -3,7 +3,8 @@ package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.DormitoryAdmin;
import com.ruoyi.system.form.RuleForm;
-import com.ruoyi.system.vo.PageVo;
+import com.ruoyi.system.form.SearchForm;
+import com.ruoyi.system.vo.PageResult;
import com.ruoyi.system.vo.ResultVo;
/**
@@ -16,6 +17,12 @@ public interface IDormitoryAdminService
{
public ResultVo login(RuleForm ruleForm);
+
+ public PageResult findAll(int page, int size);
+
+ public PageResult search(SearchForm searchForm);
+ public String validateSearchColumn(String userInputSearchType);
+
/**
* 查询宿舍管理员
*
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryService.java
index 3c26ee1..c7492ba 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IDormitoryService.java
@@ -11,6 +11,8 @@ import com.ruoyi.system.domain.Dormitory;
*/
public interface IDormitoryService
{
+
+ public List getAvailableDormitories();
/**
* 查询宿舍表
*
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IStudentService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IStudentService.java
index 32ffb2a..4447017 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IStudentService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IStudentService.java
@@ -1,7 +1,11 @@
package com.ruoyi.system.service;
import java.util.List;
+
+import com.ruoyi.system.domain.DormitoryAdmin;
import com.ruoyi.system.domain.Student;
+import com.ruoyi.system.vo.PageResult;
+import com.ruoyi.system.vo.StudentVo;
/**
* 学生表Service接口
@@ -11,6 +15,8 @@ import com.ruoyi.system.domain.Student;
*/
public interface IStudentService
{
+ public Boolean saveStudent(Student student);
+ public PageResult findAll(int page, int size);
/**
* 查询学生表
*
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryAdminServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryAdminServiceImpl.java
index 59ea8ff..153f493 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryAdminServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryAdminServiceImpl.java
@@ -3,6 +3,8 @@ package com.ruoyi.system.service.impl;
import java.util.List;
import com.ruoyi.system.form.RuleForm;
+import com.ruoyi.system.form.SearchForm;
+import com.ruoyi.system.vo.PageResult;
import com.ruoyi.system.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -22,7 +24,6 @@ public class DormitoryAdminServiceImpl implements IDormitoryAdminService
@Autowired
private DormitoryAdminMapper dormitoryAdminMapper;
-
@Override
public ResultVo login(RuleForm ruleForm)
{
@@ -41,6 +42,70 @@ public class DormitoryAdminServiceImpl implements IDormitoryAdminService
return resultVO;
}
+ public PageResult findAll(int page, int size) {
+ int offset = page * size;
+ List dormitoryAdmins = dormitoryAdminMapper.findDormitoryAdminsByPage(offset, size);
+ int totalElements = dormitoryAdminMapper.countDormitoryAdmins();
+ return new PageResult<>(dormitoryAdmins, totalElements);
+ }
+
+ public String validateSearchColumn(String userInputSearchType) {
+ // 实现你的验证逻辑,例如检查输入是否在允许的列名列表中
+ // 这里只是一个示例,你应该根据你的需求来实现这个逻辑
+ String[] allowedColumns = {"username", "name", "telephone"}; // 假设这些是你允许的列名
+ for (String allowedColumn : allowedColumns) {
+ if (allowedColumn.equalsIgnoreCase(userInputSearchType)) {
+ return allowedColumn; // 返回经过验证的列名
+ }
+ }
+ return null; // 如果没有找到匹配的列名,则返回null
+ }
+ /*public List searchDormitoryAdmins(String userInputSearchType, String searchValue, int page, int pageSize) {
+ // 在这里,你应该验证userInputSearchType是否是一个有效的列名
+ // 例如,你可以维护一个允许的列名列表,并检查userInputSearchType是否在这个列表中
+ String validatedSearchColumn = validateSearchColumn(userInputSearchType);
+
+ if (validatedSearchColumn == null) {
+ // 处理无效的搜索类型
+ throw new IllegalArgumentException("Invalid search type");
+ }
+
+ int offset = (page - 1) * pageSize;
+
+ return dormitoryAdminMapper.findDormitoryAdminsByValueAndPage(
+ validatedSearchColumn,
+ searchValue,
+ offset,
+ pageSize
+ );
+ }*/
+ @Override
+ public PageResult search(SearchForm searchForm) {
+ //模糊查询加分页
+ int offset = (searchForm.getPage()-1) * searchForm.getSize();
+
+ // 模糊查询加分页
+ List dormitoryAdmins;
+ int totalElements;
+
+ if (searchForm.getValue().trim().isEmpty()) {
+ // 如果没有搜索值,直接分页查询
+ dormitoryAdmins = dormitoryAdminMapper.findDormitoryAdminsByPage(offset, searchForm.getSize());
+ totalElements = dormitoryAdminMapper.countDormitoryAdmins();
+ } else {
+ String validatedSearchColumn = validateSearchColumn(searchForm.getKey());
+ if (validatedSearchColumn == null) {
+ // 如果无效的搜索类型,直接返回空结果
+ return new PageResult<>(null, 0);
+ }
+ // 如果有搜索值,执行模糊查询
+ dormitoryAdmins = dormitoryAdminMapper.findDormitoryAdminsByValueAndPage(validatedSearchColumn, searchForm.getValue(),offset, searchForm.getSize());
+ // 获取模糊查询后的总记录数
+ totalElements = dormitoryAdminMapper.countDormitoryAdminsByValue(validatedSearchColumn,searchForm.getValue());
+ }
+ // 封装分页结果
+ return new PageResult<>(dormitoryAdmins, totalElements);
+ }
/**
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryServiceImpl.java
index 0b13a3b..e05bd44 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DormitoryServiceImpl.java
@@ -19,6 +19,10 @@ public class DormitoryServiceImpl implements IDormitoryService
@Autowired
private DormitoryMapper dormitoryMapper;
+ public List getAvailableDormitories() {
+ // 使用自定义 Mapper 来查询可用的宿舍
+ return dormitoryMapper.selectAvailableDormitories();
+ }
/**
* 查询宿舍表
*
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/StudentServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/StudentServiceImpl.java
index 5cab908..798e9de 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/StudentServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/StudentServiceImpl.java
@@ -1,6 +1,12 @@
package com.ruoyi.system.service.impl;
import java.util.List;
+
+import com.ruoyi.system.domain.Dormitory;
+import com.ruoyi.system.domain.DormitoryAdmin;
+import com.ruoyi.system.mapper.DormitoryMapper;
+import com.ruoyi.system.util.CommonUtil;
+import com.ruoyi.system.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.StudentMapper;
@@ -18,6 +24,37 @@ public class StudentServiceImpl implements IStudentService
{
@Autowired
private StudentMapper studentMapper;
+ @Autowired
+ private DormitoryMapper dormitoryMapper;
+
+ @Override
+ public Boolean saveStudent(Student student) {
+ //添加学生数据
+ student.setState("入住");
+ student.setCreateDate(CommonUtil.createData());
+ int insert = this.studentMapper.insertStudent(student);
+ if(insert != 1){
+ return false;
+ }
+ //更新宿舍信息
+ Dormitory dormitory = dormitoryMapper.selectDormitoryById(student.getDormitoryId());
+ if(dormitory.getAvailabe() == 0){
+ return false;
+ }
+ dormitory.setAvailabe(dormitory.getAvailabe() - 1);
+ int update = dormitoryMapper.updateDormitory(dormitory);
+ if(update != 1)
+ return false;
+ return true;
+ }
+
+ @Override
+ public PageResult findAll(int page, int size) {
+ int offset = page * size;
+ List students = studentMapper.findDormitoryAdminsByPage(offset, size);
+ int totalElements = studentMapper.countDormitoryAdmins();
+ return new PageResult<>(students, totalElements);
+ }
/**
* 查询学生表
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/vo/PageVo.java b/ruoyi-system/src/main/java/com/ruoyi/system/vo/PageVo.java
deleted file mode 100644
index c3350a5..0000000
--- a/ruoyi-system/src/main/java/com/ruoyi/system/vo/PageVo.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.ruoyi.system.vo;
-
-
-import lombok.Data;
-
-@Data
-public class PageVo {
- private Object data;
- private Long total;
-}
diff --git a/ruoyi-system/src/main/resources/mapper/system/DormitoryAdminMapper.xml b/ruoyi-system/src/main/resources/mapper/system/DormitoryAdminMapper.xml
index 76d25de..3e2f4cd 100644
--- a/ruoyi-system/src/main/resources/mapper/system/DormitoryAdminMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/DormitoryAdminMapper.xml
@@ -37,7 +37,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
FROM dormitory_admin
WHERE username = #{username}
-
+
+
+
+
insert into dormitory_admin
diff --git a/ruoyi-system/src/main/resources/mapper/system/StudentMapper.xml b/ruoyi-system/src/main/resources/mapper/system/StudentMapper.xml
index 5a16be7..152c3e4 100644
--- a/ruoyi-system/src/main/resources/mapper/system/StudentMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/StudentMapper.xml
@@ -9,9 +9,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-
+
-
+
@@ -34,6 +34,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
+
+
insert into student