parent
4c64ad2731
commit
32463b374b
@ -0,0 +1,73 @@
|
||||
package com.yanzhen.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.yanzhen.entity.Building;
|
||||
import com.yanzhen.entity.User;
|
||||
import com.yanzhen.service.BuildingService楼层设置;
|
||||
import com.yanzhen.service.UserService用户管理;
|
||||
import com.yanzhen.utils.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController // 标记为RESTful控制器
|
||||
@RequestMapping("/building") // 映射URL路径到该控制器
|
||||
public class BuildingController {
|
||||
|
||||
@Autowired // 自动注入BuildingService
|
||||
private BuildingService楼层设置 buildingService;
|
||||
@Autowired // 自动注入UserService
|
||||
private UserService用户管理 userService;
|
||||
|
||||
@PostMapping("create") // 映射POST请求到create方法
|
||||
public Result create(@RequestBody Building building){ // 接收JSON格式的楼宇对象
|
||||
int flag = buildingService.create(building); // 调用服务层创建楼宇
|
||||
if(flag>0){ // 如果创建成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果创建失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("delete") // 映射GET请求到delete方法
|
||||
public Result delete(String ids){ // 接收楼宇ID字符串
|
||||
int flag = buildingService.delete(ids); // 调用服务层删除楼宇
|
||||
if(flag>0){ // 如果删除成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果删除失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("update") // 映射POST请求到update方法
|
||||
public Result update(@RequestBody Building building){ // 接收JSON格式的楼宇对象
|
||||
int flag = buildingService.update(building); // 调用服务层更新楼宇信息
|
||||
if(flag>0){ // 如果更新成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果更新失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("detail") // 映射GET请求到detail方法
|
||||
public Building detail(Integer id){ // 接收楼宇ID
|
||||
return buildingService.detail(id); // 调用服务层获取楼宇详情并返回
|
||||
}
|
||||
|
||||
@PostMapping("query") // 映射POST请求到query方法
|
||||
public Map<String,Object> query(@RequestBody Building building, HttpServletRequest request){ // 接收JSON格式的楼宇对象和HTTP请求
|
||||
User param = (User)request.getAttribute("user"); // 从请求中获取用户信息
|
||||
User loginUser = userService.detail(param.getId()); // 调用服务层获取用户详情
|
||||
if(loginUser.getType() == 1){ // 如果用户是宿管员
|
||||
building.setUserId(loginUser.getId()); // 设置楼宇的用户ID为当前登录用户的ID
|
||||
}
|
||||
PageInfo<Building> pageInfo = buildingService.query(building); // 调用服务层查询楼宇列表
|
||||
pageInfo.getList().forEach(entity->{ // 遍历查询结果中的每个楼宇
|
||||
User user = userService.detail(entity.getUserId()); // 调用服务层获取每个楼宇的用户信息
|
||||
entity.setUser(user); // 将用户信息设置到楼宇对象中
|
||||
});
|
||||
return Result.ok(pageInfo); // 返回查询结果
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package com.yanzhen.service; // 定义包名
|
||||
|
||||
import com.yanzhen.entity.Bed; // 导入Bed实体类
|
||||
import com.yanzhen.entity.Building; // 导入Building实体类
|
||||
import com.yanzhen.entity.DormitorySet; // 导入DormitorySet实体类
|
||||
import com.yanzhen.mapper.BedMapper; // 导入BedMapper接口
|
||||
import com.yanzhen.mapper.BuildingMapper; // 导入BuildingMapper接口
|
||||
import com.yanzhen.mapper.DormitoryMapper; // 导入DormitoryMapper接口
|
||||
import com.yanzhen.entity.Dormitory; // 导入Dormitory实体类
|
||||
import com.github.pagehelper.PageHelper; // 导入PageHelper分页插件
|
||||
import com.github.pagehelper.PageInfo; // 导入PageInfo分页信息类
|
||||
import com.yanzhen.mapper.DormitorySetMapper; // 导入DormitorySetMapper接口
|
||||
import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的@Autowired注解
|
||||
import org.springframework.stereotype.Service; // 导入Spring的@Service注解
|
||||
import org.springframework.transaction.annotation.Transactional; // 导入Spring的@Transactional注解
|
||||
import org.springframework.util.StringUtils; // 导入Spring的StringUtils工具类
|
||||
|
||||
import java.util.List; // 导入Java的List集合类
|
||||
|
||||
@Service // 标注这是一个服务层的Bean
|
||||
public class DormitoryService宿舍编号设置 {// “宿舍编号设置----管理员”
|
||||
|
||||
@Autowired // 自动注入DormitoryMapper依赖
|
||||
private DormitoryMapper dormitoryMapper;
|
||||
@Autowired // 自动注入DormitorySetMapper依赖
|
||||
private DormitorySetMapper dormitorySetMapper;
|
||||
@Autowired // 自动注入BuildingMapper依赖
|
||||
private BuildingMapper buildingMapper;
|
||||
@Autowired // 自动注入BedMapper依赖
|
||||
private BedMapper bedMapper;
|
||||
|
||||
public int create(Dormitory dormitory) { // 创建宿舍记录
|
||||
return dormitoryMapper.create(dormitory); // 调用DormitoryMapper的create方法
|
||||
}
|
||||
|
||||
public int delete(String ids) { // 根据ID字符串批量删除宿舍记录
|
||||
String[] arr = ids.split(","); // 将ID字符串按逗号分割成数组
|
||||
int row = 0; // 初始化删除计数器
|
||||
for (String s : arr) { // 遍历ID数组
|
||||
if(!StringUtils.isEmpty(s)){ // 如果ID不为空
|
||||
dormitoryMapper.delete(Integer.parseInt(s)); // 调用DormitoryMapper的delete方法删除记录
|
||||
row++; // 删除计数器加1
|
||||
}
|
||||
}
|
||||
return row; // 返回删除的记录数
|
||||
}
|
||||
|
||||
public int delete(Integer id) { // 根据ID删除单个宿舍记录
|
||||
return dormitoryMapper.delete(id); // 调用DormitoryMapper的delete方法
|
||||
}
|
||||
|
||||
public int update(Dormitory dormitory) { // 更新宿舍记录
|
||||
return dormitoryMapper.update(dormitory); // 调用DormitoryMapper的update方法
|
||||
}
|
||||
|
||||
public int updateSelective(Dormitory dormitory) { // 选择性更新宿舍记录
|
||||
return dormitoryMapper.updateSelective(dormitory); // 调用DormitoryMapper的updateSelective方法
|
||||
}
|
||||
|
||||
public PageInfo<Dormitory> query(Dormitory dormitory) { // 查询宿舍记录并分页
|
||||
if(dormitory != null && dormitory.getPage() != null){ // 如果宿舍对象和分页信息不为空
|
||||
PageHelper.startPage(dormitory.getPage(),dormitory.getLimit()); // 设置分页参数
|
||||
}
|
||||
return new PageInfo<Dormitory>(dormitoryMapper.query(dormitory)); // 返回分页后的宿舍记录列表
|
||||
}
|
||||
|
||||
public Dormitory detail(Integer id) { // 根据ID查询单个宿舍详情
|
||||
return dormitoryMapper.detail(id); // 调用DormitoryMapper的detail方法
|
||||
}
|
||||
|
||||
public int count(Dormitory dormitory) { // 统计符合条件的宿舍记录数
|
||||
return dormitoryMapper.count(dormitory); // 调用DormitoryMapper的count方法
|
||||
}
|
||||
|
||||
@Transactional // 声明该方法需要事务管理
|
||||
public void init(Dormitory dormitory){ // 初始化宿舍数据
|
||||
DormitorySet param = new DormitorySet(); // 创建DormitorySet对象
|
||||
param.setBuildingId(dormitory.getBuildingId()); // 设置建筑ID
|
||||
param.setStoreyId(dormitory.getStoreyId()); // 设置楼层ID
|
||||
List<DormitorySet> dormitorySets = dormitorySetMapper.query(param); // 查询宿舍设置信息
|
||||
Building building = buildingMapper.detail(dormitory.getBuildingId()); // 查询建筑详细信息
|
||||
|
||||
//删除已有床位(先查询出来,然后批量删除)
|
||||
List<Dormitory> dormitoryList = dormitoryMapper.query(dormitory); // 查询现有的宿舍记录
|
||||
dormitoryList.forEach(item->{ // 遍历宿舍记录列表
|
||||
bedMapper.deleteByDormitoryId(item.getId()); // 删除每个宿舍对应的床位记录
|
||||
});
|
||||
//删除以有的数据(删除已有宿舍)
|
||||
dormitoryMapper.deleteByBuildingIdAndStoryId(dormitory.getBuildingId(),dormitory.getStoreyId()); // 删除指定建筑和楼层的所有宿舍记录
|
||||
|
||||
dormitorySets.forEach(dormitorySet -> { // 遍历宿舍设置信息列表
|
||||
|
||||
for(int i=dormitorySet.getStart();i<=dormitorySet.getEnd();i++){ // 根据起始和结束编号生成宿舍编号
|
||||
Dormitory entity = new Dormitory(); // 创建新的宿舍对象
|
||||
entity.setNo(dormitorySet.getPrefix()+i); // 设置宿舍编号
|
||||
entity.setBuildingId(dormitory.getBuildingId()); // 设置建筑ID
|
||||
entity.setStoreyId(dormitory.getStoreyId()); // 设置楼层ID
|
||||
entity.setCapacity(dormitorySet.getCapacity()); // 设置宿舍容量
|
||||
entity.setSex(building.getSex()); // 设置宿舍性别限制
|
||||
entity.setType(building.getType()); // 设置宿舍类型
|
||||
dormitoryMapper.create(entity); // 创建新的宿舍记录
|
||||
for(int j=1;j<=entity.getCapacity();j++){ // 根据宿舍容量生成床位记录
|
||||
Bed bed = new Bed(); // 创建新的床位对象
|
||||
bed.setBno(entity.getNo()+"-"+j); // 设置床位编号
|
||||
bed.setDormitoryId(entity.getId()); // 设置所属宿舍ID
|
||||
bedMapper.create(bed); // 创建新的床位记录
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.yanzhen.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.yanzhen.entity.DormitorySet;
|
||||
import com.yanzhen.service.DormitorySetService宿舍设置增删查改数据库;
|
||||
import com.yanzhen.utils.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController // 声明这是一个控制器,并且返回的数据直接写入 HTTP 响应体中,而不是解析为跳转路径。
|
||||
@RequestMapping("/dormitorySet") // 设置请求的根路径为 /dormitorySet
|
||||
public class DormitorySetController { // 定义一个名为 DormitorySetController 的类
|
||||
|
||||
@Autowired // 自动注入 DormitorySetService 对象
|
||||
private DormitorySetService宿舍设置增删查改数据库 dormitorySetService;
|
||||
|
||||
@PostMapping("create") // 映射 HTTP POST 请求到 create 方法
|
||||
public Result create(@RequestBody DormitorySet dormitorySet){ // 从请求体中获取 DormitorySet 对象
|
||||
int flag = dormitorySetService.create(dormitorySet); // 调用服务层的 create 方法创建记录
|
||||
if(flag>0){ // 如果创建成功
|
||||
return Result.ok(); // 返回成功的 Result 对象
|
||||
}else{ // 如果创建失败
|
||||
return Result.fail(); // 返回失败的 Result 对象
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("delete") // 映射 HTTP GET 请求到 delete 方法
|
||||
public Result delete(String ids){ // 从请求参数中获取要删除的记录 ID
|
||||
int flag = dormitorySetService.delete(ids); // 调用服务层的 delete 方法删除记录
|
||||
if(flag>0){ // 如果删除成功
|
||||
return Result.ok(); // 返回成功的 Result 对象
|
||||
}else{ // 如果删除失败
|
||||
return Result.fail(); // 返回失败的 Result 对象
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("update") // 映射 HTTP POST 请求到 update 方法
|
||||
public Result update(@RequestBody DormitorySet dormitorySet){ // 从请求体中获取 DormitorySet 对象
|
||||
int flag = dormitorySetService.update(dormitorySet); // 调用服务层的 update 方法更新记录
|
||||
if(flag>0){ // 如果更新成功
|
||||
return Result.ok(); // 返回成功的 Result 对象
|
||||
}else{ // 如果更新失败
|
||||
return Result.fail(); // 返回失败的 Result 对象
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("detail") // 映射 HTTP GET 请求到 detail 方法
|
||||
public DormitorySet detail(Integer id){ // 从请求参数中获取记录 ID
|
||||
return dormitorySetService.detail(id); // 调用服务层的 detail 方法获取记录详情并返回
|
||||
}
|
||||
|
||||
@PostMapping("query") // 映射 HTTP POST 请求到 query 方法
|
||||
public Map<String,Object> query(@RequestBody DormitorySet dormitorySet){ // 从请求体中获取 DormitorySet 对象作为查询条件
|
||||
PageInfo<DormitorySet> pageInfo = dormitorySetService.query(dormitorySet); // 调用服务层的 query 方法进行分页查询
|
||||
return Result.ok(pageInfo); // 返回包含查询结果的成功的 Result 对象
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.yanzhen.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.yanzhen.entity.DormitoryStudent;
|
||||
import com.yanzhen.entity.Student;
|
||||
import com.yanzhen.service.DormitoryService宿舍编号设置;
|
||||
import com.yanzhen.service.DormitoryStudentService宿舍预选设置;
|
||||
import com.yanzhen.service.StudentService学生管理;
|
||||
import com.yanzhen.utils.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController // 声明这是一个控制器,并且返回的数据直接写入 HTTP 响应体中,而不是解析为跳转路径。
|
||||
@RequestMapping("/dormitoryStudent") // 设置请求的根路径为 /dormitoryStudent
|
||||
public class DormitoryStudentController {
|
||||
|
||||
@Autowired // 自动注入DormitoryStudentService实例
|
||||
private DormitoryStudentService宿舍预选设置 dormitoryStudentService;
|
||||
|
||||
@Autowired // 自动注入StudentService实例
|
||||
private StudentService学生管理 studentService;
|
||||
|
||||
@Autowired // 自动注入DormitoryService实例
|
||||
private DormitoryService宿舍编号设置 dormitoryService;
|
||||
|
||||
@PostMapping("create") // 映射HTTP POST请求到 create 方法
|
||||
public Result create(@RequestBody DormitoryStudent dormitoryStudent){ // 从请求体中获取 DormitoryStudent 对象
|
||||
int flag = dormitoryStudentService.create(dormitoryStudent); // 调用服务层创建学生宿舍记录
|
||||
if(flag>0){ // 如果创建成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果创建失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("delete") // 映射HTTP GET请求到 delete 方法
|
||||
public Result delete(String ids){ // 接收要删除的学生宿舍记录的ID字符串
|
||||
int flag = dormitoryStudentService.delete(ids); // 调用服务层删除指定ID的学生宿舍记录
|
||||
if(flag>0){ // 如果删除成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果删除失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("update") // 映射HTTP POST请求到 update 方法
|
||||
public Result update(@RequestBody DormitoryStudent dormitoryStudent){ // 从请求体中获取 DormitoryStudent 对象
|
||||
int flag = dormitoryStudentService.update(dormitoryStudent); // 调用服务层更新学生宿舍记录
|
||||
if(flag>0){ // 如果更新成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果更新失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("detail") // 映射HTTP GET请求到 detail 方法
|
||||
public DormitoryStudent detail(Integer id){ // 接收学生宿舍记录的ID
|
||||
return dormitoryStudentService.detail(id); // 调用服务层获取指定ID的学生宿舍记录详情并返回
|
||||
}
|
||||
|
||||
@PostMapping("query") // 映射HTTP POST请求到 query 方法
|
||||
public Map<String,Object> query(@RequestBody DormitoryStudent dormitoryStudent){ // 从请求体中获取 DormitoryStudent 对象用于查询条件
|
||||
PageInfo<DormitoryStudent> pageInfo = dormitoryStudentService.query(dormitoryStudent); // 调用服务层进行分页查询
|
||||
pageInfo.getList().forEach(entity->{ // 遍历查询结果列表
|
||||
Student detail = studentService.detail(entity.getStudentId()); // 获取每个学生宿舍记录对应的学生详细信息
|
||||
entity.setStudent(detail); // 将学生信息设置到学生宿舍记录中
|
||||
});
|
||||
return Result.ok(pageInfo); // 返回包含分页信息和查询结果的成功结果
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.yanzhen.framework.mvc; // 定义包名
|
||||
|
||||
import com.yanzhen.framework.exception.MyException; // 导入自定义异常类
|
||||
import com.yanzhen.utils.Result; // 导入结果处理工具类
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice; // 导入Spring MVC的ControllerAdvice注解
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler; // 导入Spring MVC的ExceptionHandler注解
|
||||
import org.springframework.web.bind.annotation.RequestBody; // 导入Spring MVC的RequestBody注解
|
||||
import org.springframework.web.bind.annotation.ResponseBody; // 导入Spring MVC的ResponseBody注解
|
||||
|
||||
@ControllerAdvice // 标记该类为全局异常处理类
|
||||
public class GlobalControllerAdvice {
|
||||
|
||||
@ExceptionHandler(RuntimeException.class) // 处理所有RuntimeException类型的异常
|
||||
@ResponseBody // 将返回值作为HTTP响应体
|
||||
public Result handle(RuntimeException exception){ // 定义处理方法,参数为捕获到的异常
|
||||
exception.printStackTrace(); // 打印异常堆栈信息
|
||||
return Result.fail(exception.getMessage()); // 返回失败的结果对象,包含异常信息
|
||||
}
|
||||
|
||||
@ExceptionHandler(MyException.class) // 处理所有MyException类型的异常
|
||||
@ResponseBody // 将返回值作为HTTP响应体
|
||||
public Result handle(MyException exception){ // 定义处理方法,参数为捕获到的异常
|
||||
exception.printStackTrace(); // 打印异常堆栈信息
|
||||
return Result.fail(Result.TOKEN_ERROR,exception.getMessage()); // 返回失败的结果对象,包含错误码和异常信息
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.yanzhen.service; // 定义包名
|
||||
|
||||
import com.yanzhen.mapper.MenuMapper; // 导入MenuMapper接口
|
||||
import com.yanzhen.entity.Menu; // 导入Menu实体类
|
||||
import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的自动装配注解
|
||||
import org.springframework.stereotype.Service; // 导入Spring的服务层注解
|
||||
|
||||
import java.util.List; // 导入List集合类
|
||||
|
||||
@Service // 标记为服务层组件
|
||||
public class MenuService菜单 { // 定义MenuService类
|
||||
|
||||
@Autowired // 自动注入MenuMapper依赖
|
||||
private MenuMapper menuMapper;
|
||||
|
||||
public List<Menu> query(Integer userId){ // 根据用户ID查询对应菜单列表
|
||||
return menuMapper.query(userId); // 调用menuMapper的query方法并返回结果
|
||||
}
|
||||
public List<Menu> list(){ // 查询所有菜单的方法
|
||||
return menuMapper.list(); // 调用menuMapper的list方法并返回结果
|
||||
}
|
||||
|
||||
public List<Integer> queryCheckMenuId(Integer userId){ // 根据用户ID查询选中的菜单ID的方法
|
||||
return menuMapper.queryCheckMenuId(userId); // 调用menuMapper的queryCheckMenuId方法并返回结果
|
||||
}
|
||||
|
||||
public List<Menu> queryByType(){ // 按类型查询菜单的方法
|
||||
return menuMapper.queryByType(); // 调用menuMapper的queryByType方法并返回结果
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.yanzhen.mapper; // 定义包名
|
||||
|
||||
import java.util.List; // 导入List集合类
|
||||
import java.util.Map; // 导入Map集合类
|
||||
|
||||
import com.yanzhen.entity.NoticeReceive; // 导入NoticeReceive实体类
|
||||
|
||||
public interface NoticeReceiveMapper { // 定义NoticeReceiveMapper接口
|
||||
|
||||
public int create(NoticeReceive noticeReceive); // 创建NoticeReceive记录的方法
|
||||
|
||||
public int delete(Integer id); // 根据ID删除NoticeReceive记录的方法
|
||||
|
||||
public int deleteByNoticeId(Integer noticeId); // 根据通知ID删除NoticeReceive记录的方法
|
||||
|
||||
public int update(NoticeReceive noticeReceive); // 更新NoticeReceive记录的方法
|
||||
|
||||
public int updateSelective(NoticeReceive noticeReceive); // 选择性更新NoticeReceive记录的方法
|
||||
|
||||
public List<NoticeReceive> query(NoticeReceive noticeReceive); // 查询NoticeReceive记录列表的方法
|
||||
|
||||
public NoticeReceive detail(Integer id); // 根据ID获取NoticeReceive详情的方法
|
||||
|
||||
public int count(NoticeReceive noticeReceive); // 统计NoticeReceive记录数量的方法
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package com.yanzhen.service;
|
||||
|
||||
import com.yanzhen.entity.NoticeReceive;
|
||||
import com.yanzhen.mapper.NoticeMapper;
|
||||
import com.yanzhen.entity.Notice;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.yanzhen.mapper.NoticeReceiveMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service // 标记为Spring的服务组件
|
||||
public class NoticeService公告管理 { // “公告管理----管理员/宿管”
|
||||
|
||||
@Autowired // 自动注入NoticeMapper依赖
|
||||
private NoticeMapper noticeMapper;
|
||||
@Autowired // 自动注入NoticeReceiveMapper依赖
|
||||
private NoticeReceiveMapper noticeReceiveMapper;
|
||||
|
||||
// 创建通知,并关联到多个建筑
|
||||
public int create(Notice notice) {
|
||||
noticeMapper.create(notice); // 在数据库中创建通知记录
|
||||
List<Integer> buildingIds = notice.getBuildingIds(); // 获取通知关联的建筑ID列表
|
||||
for (Integer buildingId : buildingIds) { // 遍历每个建筑ID
|
||||
NoticeReceive noticeReceive = new NoticeReceive(); // 创建新的NoticeReceive对象
|
||||
noticeReceive.setBuildingId(buildingId); // 设置建筑ID
|
||||
noticeReceive.setNoticeId(notice.getId()); // 设置通知ID
|
||||
noticeReceiveMapper.create(noticeReceive); // 在数据库中创建通知接收记录
|
||||
}
|
||||
return 1; // 返回成功标志
|
||||
}
|
||||
|
||||
// 根据逗号分隔的ID字符串批量删除通知
|
||||
public int delete(String ids) {
|
||||
String[] arr = ids.split(","); // 将ID字符串分割成数组
|
||||
int row = 0; // 初始化受影响行数计数器
|
||||
for (String s : arr) { // 遍历每个ID
|
||||
if(!StringUtils.isEmpty(s)){ // 如果ID不为空
|
||||
noticeReceiveMapper.deleteByNoticeId(Integer.parseInt(s)); // 删除相关的通知接收记录
|
||||
noticeMapper.delete(Integer.parseInt(s)); // 删除通知记录
|
||||
row++; // 增加受影响行数计数器
|
||||
}
|
||||
}
|
||||
return row; // 返回受影响行数
|
||||
}
|
||||
|
||||
// 根据单个ID删除通知
|
||||
public int delete(Integer id) {
|
||||
noticeReceiveMapper.deleteByNoticeId(id); // 删除相关的通知接收记录
|
||||
return noticeMapper.delete(id); // 删除通知记录并返回结果
|
||||
}
|
||||
|
||||
// 更新通知信息
|
||||
public int update(Notice notice) {
|
||||
return noticeMapper.update(notice); // 更新通知记录并返回结果
|
||||
}
|
||||
|
||||
// 选择性更新通知信息,同时重新关联建筑
|
||||
public int updateSelective(Notice notice) {
|
||||
noticeMapper.updateSelective(notice); // 选择性更新通知记录
|
||||
noticeReceiveMapper.deleteByNoticeId(notice.getId()); // 删除旧的通知接收记录
|
||||
List<Integer> buildingIds = notice.getBuildingIds(); // 获取新的通知关联的建筑ID列表
|
||||
for (Integer buildingId : buildingIds) { // 遍历每个建筑ID
|
||||
NoticeReceive noticeReceive = new NoticeReceive(); // 创建新的NoticeReceive对象
|
||||
noticeReceive.setBuildingId(buildingId); // 设置建筑ID
|
||||
noticeReceive.setNoticeId(notice.getId()); // 设置通知ID
|
||||
noticeReceiveMapper.create(noticeReceive); // 在数据库中创建新的通知接收记录
|
||||
}
|
||||
return 1; // 返回成功标志
|
||||
}
|
||||
|
||||
// 分页查询通知
|
||||
public PageInfo<Notice> query(Notice notice) {
|
||||
if(notice != null && notice.getPage() != null){ // 如果通知对象和分页信息不为空
|
||||
PageHelper.startPage(notice.getPage(), notice.getLimit()); // 启动分页
|
||||
}
|
||||
return new PageInfo<Notice>(noticeMapper.query(notice)); // 执行查询并返回分页结果
|
||||
}
|
||||
|
||||
// 根据建筑ID分页查询通知
|
||||
public PageInfo<Notice> queryByBuildingId(Notice notice){
|
||||
if(notice != null && notice.getPage() != null){ // 如果通知对象和分页信息不为空
|
||||
PageHelper.startPage(notice.getPage(), notice.getLimit()); // 启动分页
|
||||
}
|
||||
return new PageInfo<Notice>(noticeMapper.queryByBuildingId(notice)); // 执行查询并返回分页结果
|
||||
}
|
||||
|
||||
// 根据ID获取通知详情
|
||||
public Notice detail(Integer id) {
|
||||
return noticeMapper.detail(id); // 查询并返回通知详情
|
||||
}
|
||||
|
||||
// 统计符合条件的通知数量
|
||||
public int count(Notice notice) {
|
||||
return noticeMapper.count(notice); // 查询并返回符合条件的通知数量
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package com.yanzhen.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.yanzhen.entity.Repair;
|
||||
import com.yanzhen.entity.Student;
|
||||
import com.yanzhen.service.BuildingService楼层设置;
|
||||
import com.yanzhen.service.DormitoryService宿舍编号设置;
|
||||
import com.yanzhen.service.RepairService报修管理;
|
||||
import com.yanzhen.service.StudentService学生管理;
|
||||
import com.yanzhen.utils.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController // 声明这是一个RESTful控制器
|
||||
@RequestMapping("/repair") // 设置请求路径前缀为/repair
|
||||
public class RepairController {
|
||||
|
||||
@Autowired // 自动注入RepairService实例
|
||||
private RepairService报修管理 repairService;
|
||||
@Autowired // 自动注入StudentService实例
|
||||
private StudentService学生管理 studentService;
|
||||
@Autowired // 自动注入DormitoryService实例
|
||||
private DormitoryService宿舍编号设置 dormitoryService;
|
||||
@Autowired // 自动注入BuildingService实例
|
||||
private BuildingService楼层设置 buildingService;
|
||||
|
||||
@PostMapping("create") // 映射HTTP POST请求到create方法
|
||||
public Result create(@RequestBody Repair repair){ // 接收一个Repair对象作为请求体
|
||||
int flag = repairService.create(repair); // 调用服务层创建维修记录
|
||||
if(flag>0){ // 如果创建成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果创建失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("delete") // 映射HTTP GET请求到delete方法
|
||||
public Result delete(String ids){ // 接收要删除的记录ID字符串
|
||||
int flag = repairService.delete(ids); // 调用服务层删除指定ID的维修记录
|
||||
if(flag>0){ // 如果删除成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果删除失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("update") // 映射HTTP POST请求到update方法
|
||||
public Result update(@RequestBody Repair repair){ // 接收一个Repair对象作为请求体
|
||||
int flag = repairService.updateSelective(repair); // 调用服务层更新维修记录,只更新非空字段
|
||||
if(flag>0){ // 如果更新成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果更新失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("detail") // 映射HTTP GET请求到detail方法
|
||||
public Repair detail(Integer id){ // 接收维修记录的ID
|
||||
return repairService.detail(id); // 调用服务层获取指定ID的维修记录详情并返回
|
||||
}
|
||||
|
||||
@PostMapping("query") // 映射HTTP POST请求到query方法
|
||||
public Map<String,Object> query(@RequestBody Repair repair){ // 接收一个Repair对象作为查询条件
|
||||
PageInfo<Repair> pageInfo = new PageInfo<>(); // 创建一个分页信息对象
|
||||
if(repair.getName() != null){ // 如果查询条件中包含学生姓名
|
||||
Student detailId = studentService.detailByName(repair.getName()); // 根据姓名查找学生ID
|
||||
if(detailId != null){ // 如果找到对应的学生ID
|
||||
repair.setStudentId(detailId.getId()); // 设置查询条件的studentId属性
|
||||
}else{ // 如果没有找到对应的学生ID
|
||||
pageInfo.setList(null); // 设置分页列表为空
|
||||
pageInfo.setSize(0); // 设置分页大小为0
|
||||
return Result.ok(pageInfo); // 返回空的查询结果
|
||||
}
|
||||
}
|
||||
pageInfo = repairService.query(repair); // 调用服务层进行查询操作
|
||||
pageInfo.getList().forEach(entity->{ // 遍历查询结果列表
|
||||
entity.setBuilding(buildingService.detail(entity.getBuildingId())); // 设置每个维修记录的楼宇信息
|
||||
entity.setStudent(studentService.detail(entity.getStudentId())); // 设置每个维修记录的学生信息
|
||||
entity.setDormitory(dormitoryService.detail(entity.getDormitoryId())); // 设置每个维修记录的宿舍信息
|
||||
});
|
||||
return Result.ok(pageInfo); // 返回查询结果
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.yanzhen.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.yanzhen.entity.SelectionDormitory;
|
||||
import com.yanzhen.service.SelectionDormitoryService宿舍管理;
|
||||
import com.yanzhen.utils.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController // 声明这是一个控制器,并且返回的数据直接写入 HTTP 响应体中,而不是解析为跳转路径。
|
||||
@RequestMapping("/selectionDormitory") // 设置请求的根路径为 "/selectionDormitory"
|
||||
public class SelectionDormitoryController {
|
||||
|
||||
@Autowired // 自动注入 SelectionDormitoryService 对象
|
||||
private SelectionDormitoryService宿舍管理 selectionDormitoryService;
|
||||
|
||||
@PostMapping("create") // 映射 HTTP POST 请求到 create 方法
|
||||
public Result create(@RequestBody Map<String,String> map){ // 从请求体中获取 JSON 数据并转换为 Map
|
||||
//clazzId,dormitoryIds
|
||||
String clazzId = map.get("clazzId"); // 从 Map 中获取班级ID
|
||||
String dormitoryIds = map.get("dormitoryIds"); // 从 Map 中获取宿舍ID列表
|
||||
int flag = selectionDormitoryService.create(clazzId,dormitoryIds); // 调用服务层的创建方法
|
||||
if(flag>0){ // 如果创建成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果创建失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("delete") // 映射 HTTP GET 请求到 delete 方法
|
||||
public Result delete(String ids){ // 从请求参数中获取要删除的记录ID
|
||||
int flag = selectionDormitoryService.delete(ids); // 调用服务层的删除方法
|
||||
if(flag>0){ // 如果删除成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果删除失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("update") // 映射 HTTP POST 请求到 update 方法
|
||||
public Result update(@RequestBody SelectionDormitory selectionDormitory){ // 从请求体中获取 JSON 数据并转换为 SelectionDormitory 对象
|
||||
int flag = selectionDormitoryService.update(selectionDormitory); // 调用服务层的更新方法
|
||||
if(flag>0){ // 如果更新成功
|
||||
return Result.ok(); // 返回成功结果
|
||||
}else{ // 如果更新失败
|
||||
return Result.fail(); // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("detail") // 映射 HTTP GET 请求到 detail 方法
|
||||
public SelectionDormitory detail(Integer id){ // 从请求参数中获取记录ID
|
||||
return selectionDormitoryService.detail(id); // 调用服务层的详情查询方法并返回结果
|
||||
}
|
||||
|
||||
@PostMapping("query") // 映射 HTTP POST 请求到 query 方法
|
||||
public Map<String,Object> query(@RequestBody SelectionDormitory selectionDormitory){ // 从请求体中获取 JSON 数据并转换为 SelectionDormitory 对象
|
||||
PageInfo<SelectionDormitory> pageInfo = selectionDormitoryService.query(selectionDormitory); // 调用服务层的查询方法并获取分页信息
|
||||
return Result.ok(pageInfo); // 返回包含分页信息的查询结果
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.yanzhen.service; // 定义包名
|
||||
|
||||
import com.yanzhen.mapper.SelectionDormitoryMapper; // 导入SelectionDormitoryMapper类
|
||||
import com.yanzhen.entity.SelectionDormitory; // 导入SelectionDormitory实体类
|
||||
import com.github.pagehelper.PageHelper; // 导入PageHelper分页工具类
|
||||
import com.github.pagehelper.PageInfo; // 导入PageInfo分页信息类
|
||||
import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的@Autowired注解
|
||||
import org.springframework.stereotype.Service; // 导入Spring的@Service注解
|
||||
import org.springframework.util.StringUtils; // 导入Spring的StringUtils工具类
|
||||
|
||||
@Service // 标记该类为Spring的服务层组件
|
||||
public class SelectionDormitoryService宿舍管理 {// “宿舍管理----管理员/宿管员”
|
||||
|
||||
@Autowired // 自动注入SelectionDormitoryMapper依赖
|
||||
private SelectionDormitoryMapper selectionDormitoryMapper;
|
||||
|
||||
// 创建选择宿舍记录的方法
|
||||
public int create(String clazzId, String dormitoryIds) {
|
||||
String[] arr = dormitoryIds.split(","); // 将宿舍ID字符串按逗号分割成数组
|
||||
selectionDormitoryMapper.deleteByClazzId(Integer.parseInt(clazzId)); // 根据班级ID删除已有的选择记录
|
||||
for (String s : arr) { // 遍历宿舍ID数组
|
||||
if (!StringUtils.isEmpty(s)) { // 如果宿舍ID不为空
|
||||
SelectionDormitory selectionDormitory = new SelectionDormitory(); // 创建新的选择宿舍对象
|
||||
selectionDormitory.setClazzId(Integer.parseInt(clazzId)); // 设置班级ID
|
||||
selectionDormitory.setDormitoryId(Integer.parseInt(s)); // 设置宿舍ID
|
||||
selectionDormitoryMapper.create(selectionDormitory); // 插入新的选择宿舍记录
|
||||
}
|
||||
}
|
||||
return 1; // 返回操作成功标志
|
||||
}
|
||||
|
||||
// 批量删除选择宿舍记录的方法
|
||||
public int delete(String ids) {
|
||||
String[] arr = ids.split(","); // 将ID字符串按逗号分割成数组
|
||||
int row = 0; // 初始化受影响行数计数器
|
||||
for (String s : arr) { // 遍历ID数组
|
||||
if (!StringUtils.isEmpty(s)) { // 如果ID不为空
|
||||
selectionDormitoryMapper.delete(Integer.parseInt(s)); // 删除对应的选择宿舍记录
|
||||
row++; // 增加受影响行数计数器
|
||||
}
|
||||
}
|
||||
return row; // 返回受影响行数
|
||||
}
|
||||
|
||||
// 根据ID删除选择宿舍记录的方法
|
||||
public int delete(Integer id) {
|
||||
return selectionDormitoryMapper.delete(id); // 调用Mapper方法删除记录并返回结果
|
||||
}
|
||||
|
||||
// 更新选择宿舍记录的方法
|
||||
public int update(SelectionDormitory selectionDormitory) {
|
||||
return selectionDormitoryMapper.update(selectionDormitory); // 调用Mapper方法更新记录并返回结果
|
||||
}
|
||||
|
||||
// 选择性更新选择宿舍记录的方法
|
||||
public int updateSelective(SelectionDormitory selectionDormitory) {
|
||||
return selectionDormitoryMapper.updateSelective(selectionDormitory); // 调用Mapper方法选择性更新记录并返回结果
|
||||
}
|
||||
|
||||
// 查询选择宿舍记录的方法,支持分页
|
||||
public PageInfo<SelectionDormitory> query(SelectionDormitory selectionDormitory) {
|
||||
if (selectionDormitory != null && selectionDormitory.getPage() != null) { // 如果查询条件和分页信息不为空
|
||||
PageHelper.startPage(selectionDormitory.getPage(), selectionDormitory.getLimit()); // 启动分页
|
||||
}
|
||||
return new PageInfo<SelectionDormitory>(selectionDormitoryMapper.query(selectionDormitory)); // 执行查询并返回分页信息
|
||||
}
|
||||
|
||||
// 根据ID查询选择宿舍详情的方法
|
||||
public SelectionDormitory detail(Integer id) {
|
||||
return selectionDormitoryMapper.detail(id); // 调用Mapper方法查询详情并返回结果
|
||||
}
|
||||
|
||||
// 统计选择宿舍记录数量的方法
|
||||
public int count(SelectionDormitory selectionDormitory) {
|
||||
return selectionDormitoryMapper.count(selectionDormitory); // 调用Mapper方法统计记录数量并返回结果
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package com.yanzhen.service;
|
||||
|
||||
import com.yanzhen.entity.Org;
|
||||
import com.yanzhen.entity.SelectionJoiner;
|
||||
import com.yanzhen.mapper.SelectionJoinerMapper;
|
||||
import com.yanzhen.mapper.SelectionMapper;
|
||||
import com.yanzhen.entity.Selection;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service // 标记该类为Spring的服务组件
|
||||
public class SelectionService学生查询管理 {// “学生管理----管理员”
|
||||
|
||||
@Autowired // 自动注入SelectionMapper依赖
|
||||
private SelectionMapper selectionMapper;
|
||||
@Autowired // 自动注入OrgService依赖
|
||||
private OrgService机构管理 orgService;
|
||||
|
||||
@Autowired // 自动注入SelectionJoinerMapper依赖
|
||||
private SelectionJoinerMapper selectionJoinerMapper;
|
||||
|
||||
@Transactional // 声明该方法需要事务管理
|
||||
public int create(Selection selection) {
|
||||
selectionMapper.create(selection); // 创建新的Selection记录
|
||||
List<Integer> clazzIds = selection.getClazzIds(); // 获取班级ID列表
|
||||
//筛选出对应的班级
|
||||
List<Integer> selectIds = new ArrayList(); // 初始化选择的班级ID列表
|
||||
clazzIds.forEach(item->{ // 遍历班级ID列表
|
||||
Org detail = orgService.detail(item); // 获取班级详细信息
|
||||
if(detail.getType() == 4){ // 如果班级类型为4
|
||||
selectIds.add(detail.getId()); // 将班级ID添加到选择的班级ID列表中
|
||||
}
|
||||
});
|
||||
selectIds.forEach(item->{ // 遍历选择的班级ID列表
|
||||
SelectionJoiner joiner = new SelectionJoiner(); // 创建新的SelectionJoiner对象
|
||||
joiner.setClazzId(item); // 设置班级ID
|
||||
joiner.setSelectionId(selection.getId()); // 设置Selection ID
|
||||
selectionJoinerMapper.create(joiner); // 创建新的SelectionJoiner记录
|
||||
});
|
||||
return 1; // 返回操作成功标志
|
||||
}
|
||||
|
||||
public int delete(String ids) {
|
||||
String[] arr = ids.split(","); // 将传入的ID字符串按逗号分割成数组
|
||||
int row = 0; // 初始化删除计数器
|
||||
for (String s : arr) { // 遍历ID数组
|
||||
if(!StringUtils.isEmpty(s)){ // 如果ID不为空
|
||||
selectionMapper.delete(Integer.parseInt(s)); // 根据ID删除Selection记录
|
||||
row++; // 删除计数器加一
|
||||
}
|
||||
}
|
||||
return row; // 返回删除的记录数
|
||||
}
|
||||
|
||||
public int delete(Integer id) {
|
||||
return selectionMapper.delete(id); // 根据ID删除Selection记录并返回操作结果
|
||||
}
|
||||
|
||||
public int update(Selection selection) {
|
||||
selectionMapper.update(selection); // 更新Selection记录
|
||||
//先删除已设置的信息
|
||||
selectionJoinerMapper.deleteBySelectionId(selection.getId()); // 根据Selection ID删除所有相关的SelectionJoiner记录
|
||||
List<Integer> clazzIds = selection.getClazzIds(); // 获取班级ID列表
|
||||
//筛选出对应的班级
|
||||
List<Integer> selectIds = new ArrayList(); // 初始化选择的班级ID列表
|
||||
clazzIds.forEach(item->{ // 遍历班级ID列表
|
||||
Org detail = orgService.detail(item); // 获取班级详细信息
|
||||
if(detail.getType() == 4){ // 如果班级类型为4
|
||||
selectIds.add(detail.getId()); // 将班级ID添加到选择的班级ID列表中
|
||||
}
|
||||
});
|
||||
selectIds.forEach(item->{ // 遍历选择的班级ID列表
|
||||
SelectionJoiner joiner = new SelectionJoiner(); // 创建新的SelectionJoiner对象
|
||||
joiner.setClazzId(item); // 设置班级ID
|
||||
joiner.setSelectionId(selection.getId()); // 设置Selection ID
|
||||
selectionJoinerMapper.create(joiner); // 创建新的SelectionJoiner记录
|
||||
});
|
||||
return 1; // 返回操作成功标志
|
||||
}
|
||||
|
||||
public int updateSelective(Selection selection) {
|
||||
return selectionMapper.updateSelective(selection); // 选择性更新Selection记录并返回操作结果
|
||||
}
|
||||
|
||||
public PageInfo<Selection> query(Selection selection) {
|
||||
if(selection != null && selection.getPage() != null){ // 如果Selection对象和分页信息不为空
|
||||
PageHelper.startPage(selection.getPage(),selection.getLimit()); // 启动分页查询
|
||||
}
|
||||
return new PageInfo<Selection>(selectionMapper.query(selection)); // 执行查询并返回分页结果
|
||||
}
|
||||
|
||||
public List<Selection> queryByClazzId(Integer clazzId){
|
||||
return selectionMapper.queryByClazzId(clazzId); // 根据班级ID查询Selection记录并返回结果列表
|
||||
}
|
||||
|
||||
public Selection detail(Integer id) {
|
||||
return selectionMapper.detail(id); // 根据ID查询Selection详情并返回结果
|
||||
}
|
||||
|
||||
public int count(Selection selection) {
|
||||
return selectionMapper.count(selection); // 统计符合条件的Selection记录数并返回结果
|
||||
}
|
||||
}
|
Loading…
Reference in new issue