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/SelectionDormitoryService宿舍...

77 lines
4.0 KiB

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方法统计记录数量并返回结果
}
}