You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ssgl/zsq/DormitoryStudentService宿舍预选...

97 lines
5.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.yanzhen.service; // 定义包名
import com.yanzhen.entity.Dormitory; // 导入Dormitory实体类
import com.yanzhen.mapper.DormitoryMapper; // 导入DormitoryMapper接口
import com.yanzhen.mapper.DormitoryStudentMapper; // 导入DormitoryStudentMapper接口
import com.yanzhen.entity.DormitoryStudent; // 导入DormitoryStudent实体类
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工具类
import java.util.Date; // 导入Date类
import java.util.List; // 导入List接口
import java.util.Map; // 导入Map接口
@Service // 标记为服务层组件
public class DormitoryStudentService宿 {// “宿舍预选设置--------管理员”
@Autowired // 自动注入DormitoryStudentMapper实例
private DormitoryStudentMapper dormitoryStudentMapper;
@Autowired // 自动注入DormitoryMapper实例
private DormitoryMapper dormitoryMapper;
public int create(DormitoryStudent dormitoryStudent) { // 创建宿舍学生记录
return dormitoryStudentMapper.create(dormitoryStudent); // 调用Mapper的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不为空
dormitoryStudentMapper.delete(Integer.parseInt(s)); // 调用Mapper的delete方法删除记录
row++; // 删除计数器加1
}
}
return row; // 返回删除的记录数
}
public int delete(Integer id) { // 根据ID删除宿舍学生记录
return dormitoryStudentMapper.delete(id); // 调用Mapper的delete方法
}
public int update(DormitoryStudent dormitoryStudent) { // 更新宿舍学生记录
return dormitoryStudentMapper.update(dormitoryStudent); // 调用Mapper的update方法
}
public int updateSelective(DormitoryStudent dormitoryStudent) { // 选择性更新宿舍学生记录
return dormitoryStudentMapper.updateSelective(dormitoryStudent); // 调用Mapper的updateSelective方法
}
public PageInfo<DormitoryStudent> query(DormitoryStudent dormitoryStudent) { // 查询宿舍学生记录并分页
if(dormitoryStudent != null && dormitoryStudent.getPage() != null){ // 如果查询条件和分页信息不为空
PageHelper.startPage(dormitoryStudent.getPage(),dormitoryStudent.getLimit()); // 设置分页参数
}
return new PageInfo<DormitoryStudent>(dormitoryStudentMapper.query(dormitoryStudent)); // 返回分页结果
}
public DormitoryStudent detail(Integer id) { // 根据ID查询宿舍学生详情
return dormitoryStudentMapper.detail(id); // 调用Mapper的detail方法
}
public int count(DormitoryStudent dormitoryStudent) { // 统计宿舍学生记录数
return dormitoryStudentMapper.count(dormitoryStudent); // 调用Mapper的count方法
}
public synchronized int select_dormitory_submit(Integer studentId,Integer dormitoryId,Integer bedId){ // 提交选择宿舍操作
Dormitory detail = dormitoryMapper.detail(dormitoryId); // 获取宿舍详情
int capacity = detail.getCapacity(); // 获取宿舍容量
DormitoryStudent ds = new DormitoryStudent(); // 创建新的DormitoryStudent对象
ds.setDormitoryId(dormitoryId); // 设置宿舍ID
List<DormitoryStudent> list = dormitoryStudentMapper.query(ds); // 查询该宿舍的学生列表
if(list.size() == capacity){ // 如果宿舍已满
return 0; // 返回0表示失败
}else{ // 如果宿舍未满
dormitoryStudentMapper.deleteByCond(studentId,dormitoryId); // 删除该学生在宿舍中的现有记录
DormitoryStudent entity = new DormitoryStudent(); // 创建新的DormitoryStudent对象
entity.setDormitoryId(dormitoryId); // 设置宿舍ID
entity.setBedId(bedId); // 设置床位ID
entity.setStudentId(studentId); // 设置学生ID
entity.setCheckin(new Date()); // 设置入住日期为当前日期
entity.setStatus(1); // 设置状态为1入住
dormitoryStudentMapper.create(entity); // 创建新的宿舍学生记录
}
return 1; // 返回1表示成功
}
public int countByBuildingId(Integer buildingId){ // 根据建筑ID统计宿舍学生记录数
return dormitoryStudentMapper.countByBuildingId(buildingId); // 调用Mapper的countByBuildingId方法
}
public Map<String,Object> queryStudentByBedId(Integer bedId){ // 根据床位ID查询学生信息
return dormitoryStudentMapper.queryStudentByBedId(bedId); // 调用Mapper的queryStudentByBedId方法
}
}