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/BuildingService楼层设置.java

71 lines
3.8 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.Storey; // 导入Storey实体类
import com.yanzhen.mapper.BuildingMapper; // 导入BuildingMapper接口
import com.yanzhen.entity.Building; // 导入Building实体类
import com.github.pagehelper.PageHelper; // 导入PageHelper分页工具类
import com.github.pagehelper.PageInfo; // 导入PageInfo分页信息类
import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的自动装配注解
import org.springframework.stereotype.Service; // 导入Spring的服务层注解
import org.springframework.util.StringUtils; // 导入Spring的工具类用于字符串操作
@Service // 标记为服务层组件
public class BuildingService { // 定义BuildingService类 “楼宇管理----管理员”
@Autowired // 自动注入BuildingMapper依赖
private BuildingMapper buildingMapper;
@Autowired // 自动注入StoreyService依赖
private StoreyService storeyService;
public int create(Building building) { // 创建Building记录的方法 目的 插入一条Building记录并为其创建楼层信息
int row = 0; // 初始化受影响行数为0
row = buildingMapper.create(building); // 调用Mapper方法插入Building记录
Integer storeyNum = building.getStoreyNum(); // 获取建筑的楼层数量
for(int i=1;i<=storeyNum;i++){ // 循环创建每一层
Storey storey = new Storey(); // 实例化Storey对象
storey.setBuildingId(building.getId()); // 设置Storey所属的建筑ID
storey.setName(i+"层"); // 设置Storey的名称为“X层”
storeyService.create(storey); // 调用StoreyService方法插入Storey记录
}
return row; // 返回受影响行数
}
public int delete(String ids) { // 根据多个ID删除Building记录的方法
String[] arr = ids.split(","); // 将传入的ID字符串按逗号分割成数组
int row = 0; // 初始化受影响行数为0
for (String s : arr) { // 遍历ID数组
if(!StringUtils.isEmpty(s)){ // 如果ID不为空
buildingMapper.delete(Integer.parseInt(s)); // 调用Mapper方法删除对应ID的Building记录
row++; // 受影响行数加1
}
}
return row; // 返回受影响行数
}
public int delete(Integer id) { // 根据单个ID删除Building记录的方法
return buildingMapper.delete(id); // 调用Mapper方法删除对应ID的Building记录并返回受影响行数
}
public int update(Building building) { // 更新Building记录的方法
return buildingMapper.update(building); // 调用Mapper方法更新Building记录并返回受影响行数
}
public int updateSelective(Building building) { // 选择性更新Building记录的方法
return buildingMapper.updateSelective(building); // 调用Mapper方法选择性更新Building记录并返回受影响行数
}
public PageInfo<Building> query(Building building) { // 查询Building记录的方法支持分页
if(building != null && building.getPage() != null){ // 如果Building对象和分页参数不为空
PageHelper.startPage(building.getPage(),building.getLimit()); // 启动分页,设置当前页和每页显示条数
}
return new PageInfo<Building>(buildingMapper.query(building)); // 调用Mapper方法查询Building记录并封装成PageInfo对象返回
}
public Building detail(Integer id) { // 根据ID查询Building详情的方法
return buildingMapper.detail(id); // 调用Mapper方法查询对应ID的Building记录并返回
}
public int count(Building building) { // 统计Building记录数量的方法
return buildingMapper.count(building); // 调用Mapper方法统计Building记录数量并返回
}
}