|
|
package com.itheima.service.impl; // 定义该类所在的包路径,表示是服务实现类
|
|
|
|
|
|
import com.itheima.dao.DormCleanDao; // 导入 DormCleanDao,用于与数据库交互,操作宿舍卫生相关数据
|
|
|
import com.itheima.po.DormClean; // 导入 DormClean 类,表示宿舍卫生信息实体
|
|
|
import com.itheima.po.PageInfo; // 导入 PageInfo 类,封装分页信息
|
|
|
import com.itheima.service.DormCleanService; // 导入 DormCleanService 接口,表示宿舍卫生服务
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 导入 Spring 的注解,用于自动注入依赖
|
|
|
import org.springframework.stereotype.Service; // 导入 Service 注解,表示该类是 Spring 的服务类
|
|
|
import org.springframework.transaction.annotation.Transactional; // 导入事务管理注解,用于声明事务管理
|
|
|
|
|
|
import java.util.List; // 导入 List 类,用于存储宿舍卫生信息列表
|
|
|
|
|
|
/**
|
|
|
* @program: dormitorySystem
|
|
|
* @description: 宿舍卫生服务接口实现
|
|
|
* @author: Joyrocky
|
|
|
* @create: 2019-04-24 15:19
|
|
|
**/
|
|
|
@Service("dormCleanService") // 将该类标记为 Spring 的服务类,bean 名称为 "dormCleanService"
|
|
|
@Transactional // 标明该类中的所有方法都由 Spring 管理事务
|
|
|
public class DormCleanServiceImpl implements DormCleanService { // 实现 DormCleanService 接口
|
|
|
|
|
|
// 自动注入 DormCleanDao,用于访问宿舍卫生数据
|
|
|
@Autowired
|
|
|
private DormCleanDao dormCleanDao; // Spring 会自动注入符合类型的 DormCleanDao 实现类
|
|
|
|
|
|
/**
|
|
|
* 分页查询宿舍卫生信息
|
|
|
* @param d_id 宿舍 ID
|
|
|
* @param d_dormbuilding 宿舍楼名称
|
|
|
* @param pageIndex 当前页码
|
|
|
* @param pageSize 每页显示的记录数
|
|
|
* @return 返回分页后的宿舍卫生信息
|
|
|
*/
|
|
|
@Override
|
|
|
public PageInfo<DormClean> findPageInfo(Integer d_id, String d_dormbuilding, Integer pageIndex, Integer pageSize) {
|
|
|
// 创建 PageInfo 对象来存储分页信息
|
|
|
PageInfo<DormClean> pi = new PageInfo<DormClean>();
|
|
|
pi.setPageIndex(pageIndex); // 设置当前页码
|
|
|
pi.setPageSize(pageSize); // 设置每页的记录数
|
|
|
|
|
|
// 获取符合条件的总记录数
|
|
|
Integer totalCount = dormCleanDao.totalCount(d_id, d_dormbuilding); // 调用 Dao 层方法获取总条数
|
|
|
|
|
|
if (totalCount > 0) { // 如果查询结果不为空
|
|
|
pi.setTotalCount(totalCount); // 设置总记录数
|
|
|
// 计算分页查询的起始行数,并获取当前页的宿舍卫生信息列表
|
|
|
List<DormClean> dormCleanList = dormCleanDao.getDormCleanList(d_id, d_dormbuilding,
|
|
|
(pi.getPageIndex() - 1) * pi.getPageSize(), pi.getPageSize()); // 调用 Dao 层方法获取分页数据
|
|
|
pi.setList(dormCleanList); // 设置分页对象的班级列表
|
|
|
}
|
|
|
|
|
|
return pi; // 返回分页信息对象
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取所有宿舍卫生信息
|
|
|
* @return 返回所有宿舍卫生信息的列表
|
|
|
*/
|
|
|
@Override
|
|
|
public List<DormClean> getAll() {
|
|
|
// 获取所有宿舍卫生信息并返回
|
|
|
List<DormClean> dormCleanList = dormCleanDao.getAll(); // 调用 Dao 层方法获取所有宿舍卫生信息
|
|
|
return dormCleanList; // 返回所有宿舍卫生信息
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加宿舍卫生信息
|
|
|
* @param dormclean 要添加的宿舍卫生信息
|
|
|
* @return 返回受影响的行数,1 表示成功,0 表示失败
|
|
|
*/
|
|
|
@Override
|
|
|
public int addDormClean(DormClean dormclean) {
|
|
|
// 调用 Dao 层方法将宿舍卫生信息插入数据库
|
|
|
return dormCleanDao.addDormClean(dormclean); // 返回数据库操作受影响的行数
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据 ID 删除宿舍卫生信息
|
|
|
* @param g_id 宿舍卫生信息的 ID
|
|
|
* @return 返回受影响的行数,1 表示成功,0 表示失败
|
|
|
*/
|
|
|
@Override
|
|
|
public int deleteDormClean(Integer g_id) {
|
|
|
// 调用 Dao 层方法根据 ID 删除宿舍卫生信息
|
|
|
return dormCleanDao.deleteDormClean(g_id); // 返回删除操作受影响的行数
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改宿舍卫生信息
|
|
|
* @param dormclean 要修改的宿舍卫生信息
|
|
|
* @return 返回受影响的行数,1 表示成功,0 表示失败
|
|
|
*/
|
|
|
@Override
|
|
|
public int updateDormClean(DormClean dormclean) {
|
|
|
// 调用 Dao 层方法更新宿舍卫生信息
|
|
|
return dormCleanDao.updateDormClean(dormclean); // 返回更新操作受影响的行数
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据 ID 查询宿舍卫生信息
|
|
|
* @param g_id 宿舍卫生信息的 ID
|
|
|
* @return 返回匹配的宿舍卫生信息
|
|
|
*/
|
|
|
@Override
|
|
|
public DormClean findDormCleanById(Integer g_id) {
|
|
|
// 调用 Dao 层方法根据 ID 查询宿舍卫生信息
|
|
|
DormClean d = dormCleanDao.findDormCleanById(g_id); // 获取宿舍卫生信息
|
|
|
return d; // 返回查询结果
|
|
|
}
|
|
|
}
|