完善了后端逻辑
This commit is contained in:
parent
d6a8b3f105
commit
b31ef51f62
|
@ -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
|
|
@ -49,6 +49,11 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,11 +1,18 @@
|
||||||
package com.ruoyi.system.controller;
|
package com.ruoyi.system.controller;
|
||||||
|
|
||||||
|
import java.security.Key;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.ruoyi.common.annotation.Anonymous;
|
import com.ruoyi.common.annotation.Anonymous;
|
||||||
import com.ruoyi.system.form.RuleForm;
|
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 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.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -38,6 +45,32 @@ public class DormitoryAdminController extends BaseController
|
||||||
ResultVo resultVo = this.dormitoryAdminService.login(ruleForm);
|
ResultVo resultVo = this.dormitoryAdminService.login(ruleForm);
|
||||||
return resultVo;
|
return resultVo;
|
||||||
}
|
}
|
||||||
|
@Anonymous
|
||||||
|
@GetMapping("/list/{page}/{size}")
|
||||||
|
public ResponseEntity<PageResult<DormitoryAdmin>> getAllDormitoryAdmins(
|
||||||
|
@PathVariable("page") int page, // 使用 @PathVariable 而不是 @RequestParam
|
||||||
|
@PathVariable("size") int size) { // 同样使用 @PathVariable
|
||||||
|
|
||||||
|
// 注意:通常页码从 1 开始更合理,但这里保留您的默认值 0
|
||||||
|
// 如果业务逻辑需要页码从 1 开始,您可能需要在服务层添加额外的处理
|
||||||
|
|
||||||
|
PageResult<DormitoryAdmin> pageResult = dormitoryAdminService.findAll(page-1, size);
|
||||||
|
return ResponseEntity.ok(pageResult);
|
||||||
|
}
|
||||||
|
@Anonymous
|
||||||
|
@GetMapping("/search")
|
||||||
|
public PageResult<DormitoryAdmin> 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)
|
@Log(title = "宿舍管理员", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping("/update")
|
||||||
public AjaxResult edit(@RequestBody DormitoryAdmin dormitoryAdmin)
|
public AjaxResult edit(@RequestBody DormitoryAdmin dormitoryAdmin)
|
||||||
{
|
{
|
||||||
return toAjax(dormitoryAdminService.updateDormitoryAdmin(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)
|
@Log(title = "宿舍管理员", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
public AjaxResult remove(@PathVariable Integer[] ids)
|
public AjaxResult remove(@PathVariable Integer[] ids)
|
||||||
|
|
|
@ -2,6 +2,10 @@ package com.ruoyi.system.controller;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
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.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -34,6 +38,14 @@ public class DormitoryController extends BaseController
|
||||||
@Autowired
|
@Autowired
|
||||||
private IDormitoryService dormitoryService;
|
private IDormitoryService dormitoryService;
|
||||||
|
|
||||||
|
@Anonymous
|
||||||
|
@GetMapping("/available")
|
||||||
|
public ResultVo availableList(){
|
||||||
|
List<Dormitory> list = dormitoryService.getAvailableDormitories();
|
||||||
|
ResultVo resultVo = new ResultVo();
|
||||||
|
resultVo.setData(list);
|
||||||
|
return resultVo;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 查询宿舍表列表
|
* 查询宿舍表列表
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,6 +2,11 @@ package com.ruoyi.system.controller;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
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.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -34,10 +39,31 @@ public class StudentController extends BaseController
|
||||||
@Autowired
|
@Autowired
|
||||||
private IStudentService studentService;
|
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<PageResult<Student>> listStudent(
|
||||||
|
@PathVariable("page") int page, // 使用 @PathVariable 而不是 @RequestParam
|
||||||
|
@PathVariable("size") int size) { // 同样使用 @PathVariable
|
||||||
|
|
||||||
|
// 注意:通常页码从 1 开始更合理,但这里保留您的默认值 0
|
||||||
|
// 如果业务逻辑需要页码从 1 开始,您可能需要在服务层添加额外的处理
|
||||||
|
|
||||||
|
PageResult<Student> 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")
|
@GetMapping("/list")
|
||||||
public TableDataInfo list(Student student)
|
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)
|
@Log(title = "学生表", businessType = BusinessType.EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(HttpServletResponse response, Student student)
|
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}")
|
@GetMapping(value = "/{id}")
|
||||||
public AjaxResult getInfo(@PathVariable("id") Long 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)
|
@Log(title = "学生表", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody Student student)
|
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)
|
@Log(title = "学生表", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody Student student)
|
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)
|
@Log(title = "学生表", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
public AjaxResult remove(@PathVariable Long[] ids)
|
public AjaxResult remove(@PathVariable Long[] ids)
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class Student extends BaseEntity
|
||||||
|
|
||||||
/** dormitory_id */
|
/** dormitory_id */
|
||||||
@Excel(name = "dormitory_id")
|
@Excel(name = "dormitory_id")
|
||||||
private Long dormitoryId;
|
private Long dormitory_id;
|
||||||
|
|
||||||
/** state */
|
/** state */
|
||||||
@Excel(name = "state")
|
@Excel(name = "state")
|
||||||
|
@ -40,7 +40,7 @@ public class Student extends BaseEntity
|
||||||
|
|
||||||
/** create_date */
|
/** create_date */
|
||||||
@Excel(name = "create_date")
|
@Excel(name = "create_date")
|
||||||
private String createDate;
|
private String create_date;
|
||||||
|
|
||||||
public void setId(Long id)
|
public void setId(Long id)
|
||||||
{
|
{
|
||||||
|
@ -80,12 +80,12 @@ public class Student extends BaseEntity
|
||||||
}
|
}
|
||||||
public void setDormitoryId(Long dormitoryId)
|
public void setDormitoryId(Long dormitoryId)
|
||||||
{
|
{
|
||||||
this.dormitoryId = dormitoryId;
|
this.dormitory_id = dormitoryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getDormitoryId()
|
public Long getDormitoryId()
|
||||||
{
|
{
|
||||||
return dormitoryId;
|
return dormitory_id;
|
||||||
}
|
}
|
||||||
public void setState(String state)
|
public void setState(String state)
|
||||||
{
|
{
|
||||||
|
@ -98,12 +98,12 @@ public class Student extends BaseEntity
|
||||||
}
|
}
|
||||||
public void setCreateDate(String createDate)
|
public void setCreateDate(String createDate)
|
||||||
{
|
{
|
||||||
this.createDate = createDate;
|
this.create_date = createDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCreateDate()
|
public String getCreateDate()
|
||||||
{
|
{
|
||||||
return createDate;
|
return create_date;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,6 +3,9 @@ package com.ruoyi.system.mapper;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.ruoyi.system.domain.DormitoryAdmin;
|
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接口
|
* 宿舍管理员Mapper接口
|
||||||
|
@ -13,8 +16,24 @@ import com.ruoyi.system.domain.DormitoryAdmin;
|
||||||
public interface DormitoryAdminMapper
|
public interface DormitoryAdminMapper
|
||||||
{
|
{
|
||||||
public DormitoryAdmin selectDormitoryAdminByUsername(String username);
|
public DormitoryAdmin selectDormitoryAdminByUsername(String username);
|
||||||
|
// 这是一个示例方法,用于根据分页参数查询所有DormitoryAdmin记录
|
||||||
|
@Select("SELECT * FROM dormitory_admin LIMIT #{offset}, #{limit}")
|
||||||
|
List<DormitoryAdmin> findDormitoryAdminsByPage(@Param("offset") int offset, @Param("limit") int limit);
|
||||||
|
|
||||||
/**
|
// 查询总记录数
|
||||||
|
@Select("SELECT COUNT(*) FROM dormitory_admin")
|
||||||
|
int countDormitoryAdmins();
|
||||||
|
|
||||||
|
// 这是一个自定义查询方法,用于根据名称和职位包含的条件进行分页查询
|
||||||
|
List<DormitoryAdmin> 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 宿舍管理员主键
|
* @param id 宿舍管理员主键
|
||||||
|
@ -61,4 +80,6 @@ public interface DormitoryAdminMapper
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteDormitoryAdminByIds(Integer[] ids);
|
public int deleteDormitoryAdminByIds(Integer[] ids);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.ruoyi.system.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.ruoyi.system.domain.Dormitory;
|
import com.ruoyi.system.domain.Dormitory;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 宿舍表Mapper接口
|
* 宿舍表Mapper接口
|
||||||
|
@ -11,6 +12,8 @@ import com.ruoyi.system.domain.Dormitory;
|
||||||
*/
|
*/
|
||||||
public interface DormitoryMapper
|
public interface DormitoryMapper
|
||||||
{
|
{
|
||||||
|
@Select("SELECT * FROM dormitory WHERE availabe > 0")
|
||||||
|
List<Dormitory> selectAvailableDormitories();
|
||||||
/**
|
/**
|
||||||
* 查询宿舍表
|
* 查询宿舍表
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package com.ruoyi.system.mapper;
|
package com.ruoyi.system.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.ruoyi.system.domain.DormitoryAdmin;
|
||||||
import com.ruoyi.system.domain.Student;
|
import com.ruoyi.system.domain.Student;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学生表Mapper接口
|
* 学生表Mapper接口
|
||||||
|
@ -11,6 +15,12 @@ import com.ruoyi.system.domain.Student;
|
||||||
*/
|
*/
|
||||||
public interface StudentMapper
|
public interface StudentMapper
|
||||||
{
|
{
|
||||||
|
/*@Select("SELECT * FROM student LIMIT #{offset}, #{limit}")*/
|
||||||
|
List<Student> findDormitoryAdminsByPage(@Param("offset") int offset, @Param("limit") int limit);
|
||||||
|
|
||||||
|
// 查询总记录数
|
||||||
|
@Select("SELECT COUNT(*) FROM student")
|
||||||
|
int countDormitoryAdmins();
|
||||||
/**
|
/**
|
||||||
* 查询学生表
|
* 查询学生表
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,7 +3,8 @@ package com.ruoyi.system.service;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.ruoyi.system.domain.DormitoryAdmin;
|
import com.ruoyi.system.domain.DormitoryAdmin;
|
||||||
import com.ruoyi.system.form.RuleForm;
|
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;
|
import com.ruoyi.system.vo.ResultVo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +17,12 @@ public interface IDormitoryAdminService
|
||||||
{
|
{
|
||||||
|
|
||||||
public ResultVo login(RuleForm ruleForm);
|
public ResultVo login(RuleForm ruleForm);
|
||||||
|
|
||||||
|
public PageResult<DormitoryAdmin> findAll(int page, int size);
|
||||||
|
|
||||||
|
public PageResult search(SearchForm searchForm);
|
||||||
|
public String validateSearchColumn(String userInputSearchType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询宿舍管理员
|
* 查询宿舍管理员
|
||||||
*
|
*
|
||||||
|
|
|
@ -11,6 +11,8 @@ import com.ruoyi.system.domain.Dormitory;
|
||||||
*/
|
*/
|
||||||
public interface IDormitoryService
|
public interface IDormitoryService
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public List<Dormitory> getAvailableDormitories();
|
||||||
/**
|
/**
|
||||||
* 查询宿舍表
|
* 查询宿舍表
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package com.ruoyi.system.service;
|
package com.ruoyi.system.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.ruoyi.system.domain.DormitoryAdmin;
|
||||||
import com.ruoyi.system.domain.Student;
|
import com.ruoyi.system.domain.Student;
|
||||||
|
import com.ruoyi.system.vo.PageResult;
|
||||||
|
import com.ruoyi.system.vo.StudentVo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学生表Service接口
|
* 学生表Service接口
|
||||||
|
@ -11,6 +15,8 @@ import com.ruoyi.system.domain.Student;
|
||||||
*/
|
*/
|
||||||
public interface IStudentService
|
public interface IStudentService
|
||||||
{
|
{
|
||||||
|
public Boolean saveStudent(Student student);
|
||||||
|
public PageResult<Student> findAll(int page, int size);
|
||||||
/**
|
/**
|
||||||
* 查询学生表
|
* 查询学生表
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.ruoyi.system.service.impl;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.ruoyi.system.form.RuleForm;
|
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 com.ruoyi.system.vo.ResultVo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -22,7 +24,6 @@ public class DormitoryAdminServiceImpl implements IDormitoryAdminService
|
||||||
@Autowired
|
@Autowired
|
||||||
private DormitoryAdminMapper dormitoryAdminMapper;
|
private DormitoryAdminMapper dormitoryAdminMapper;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultVo login(RuleForm ruleForm)
|
public ResultVo login(RuleForm ruleForm)
|
||||||
{
|
{
|
||||||
|
@ -41,6 +42,70 @@ public class DormitoryAdminServiceImpl implements IDormitoryAdminService
|
||||||
return resultVO;
|
return resultVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PageResult<DormitoryAdmin> findAll(int page, int size) {
|
||||||
|
int offset = page * size;
|
||||||
|
List<DormitoryAdmin> 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<DormitoryAdmin> 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<DormitoryAdmin> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,6 +19,10 @@ public class DormitoryServiceImpl implements IDormitoryService
|
||||||
@Autowired
|
@Autowired
|
||||||
private DormitoryMapper dormitoryMapper;
|
private DormitoryMapper dormitoryMapper;
|
||||||
|
|
||||||
|
public List<Dormitory> getAvailableDormitories() {
|
||||||
|
// 使用自定义 Mapper 来查询可用的宿舍
|
||||||
|
return dormitoryMapper.selectAvailableDormitories();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 查询宿舍表
|
* 查询宿舍表
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
package com.ruoyi.system.service.impl;
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.system.mapper.StudentMapper;
|
import com.ruoyi.system.mapper.StudentMapper;
|
||||||
|
@ -18,6 +24,37 @@ public class StudentServiceImpl implements IStudentService
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
private StudentMapper studentMapper;
|
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<Student> findAll(int page, int size) {
|
||||||
|
int offset = page * size;
|
||||||
|
List<Student> students = studentMapper.findDormitoryAdminsByPage(offset, size);
|
||||||
|
int totalElements = studentMapper.countDormitoryAdmins();
|
||||||
|
return new PageResult<>(students, totalElements);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询学生表
|
* 查询学生表
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package com.ruoyi.system.vo;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class PageVo {
|
|
||||||
private Object data;
|
|
||||||
private Long total;
|
|
||||||
}
|
|
|
@ -37,7 +37,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
FROM dormitory_admin
|
FROM dormitory_admin
|
||||||
WHERE username = #{username}
|
WHERE username = #{username}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="findAll" resultType="com.ruoyi.system.domain.DormitoryAdmin">
|
||||||
|
SELECT * FROM dormitory_admin
|
||||||
|
LIMIT #{offset}, #{limit}
|
||||||
|
</select>
|
||||||
|
<select id="findDormitoryAdminsByValueAndPage" resultType="com.ruoyi.system.domain.DormitoryAdmin">
|
||||||
|
SELECT *
|
||||||
|
FROM dormitory_admin
|
||||||
|
WHERE ${searchColumn} LIKE CONCAT('%', #{searchValue}, '%')
|
||||||
|
LIMIT #{offset}, #{size}
|
||||||
|
</select>
|
||||||
|
<select id="countDormitoryAdminsByValue" resultType="java.lang.Integer">
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM dormitory_admin
|
||||||
|
WHERE ${searchColumn} LIKE CONCAT('%', #{searchValue}, '%')
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<insert id="insertDormitoryAdmin" parameterType="DormitoryAdmin" useGeneratedKeys="true" keyProperty="id">
|
<insert id="insertDormitoryAdmin" parameterType="DormitoryAdmin" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into dormitory_admin
|
insert into dormitory_admin
|
||||||
|
|
|
@ -9,9 +9,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<result property="number" column="number" />
|
<result property="number" column="number" />
|
||||||
<result property="name" column="name" />
|
<result property="name" column="name" />
|
||||||
<result property="gender" column="gender" />
|
<result property="gender" column="gender" />
|
||||||
<result property="dormitoryId" column="dormitory_id" />
|
<result property="dormitory_id" column="dormitory_id" />
|
||||||
<result property="state" column="state" />
|
<result property="state" column="state" />
|
||||||
<result property="createDate" column="create_date" />
|
<result property="create_date" column="create_date" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectStudentVo">
|
<sql id="selectStudentVo">
|
||||||
|
@ -34,6 +34,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<include refid="selectStudentVo"/>
|
<include refid="selectStudentVo"/>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="findDormitoryAdminsByPage" resultType="com.ruoyi.system.domain.Student">
|
||||||
|
select id, number, name, gender, dormitory_id, state, create_date
|
||||||
|
from student
|
||||||
|
limit #{offset}, #{limit}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<insert id="insertStudent" parameterType="Student" useGeneratedKeys="true" keyProperty="id">
|
<insert id="insertStudent" parameterType="Student" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into student
|
insert into student
|
||||||
|
|
Loading…
Reference in New Issue