上传代码

This commit is contained in:
2026-04-14 13:19:07 +08:00
parent 4df67b5cec
commit 75e75cba2c
10 changed files with 3283 additions and 0 deletions

View File

@@ -0,0 +1,136 @@
package com.hrs.dao;
import com.hrs.model.entity.Collection;
import java.util.List;
/**
* Copyright: Copyright (c) 2026 chinasofti
*
* @ClassName: CollectionDao.java
* @Description: 收藏数据层
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2026年4月13日 上午9:30:25
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2026年4月13日 赵恒 v1.0.0 新建文件
*/
public interface CollectionDao {
/**
*
* @Function: add
* @Description: 添加收藏
*
* @param: collection 收藏对象
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:37:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean add(Collection collection);
/**
*
* @Function: isCollected
* @Description: 判断是否已收藏
*
* @param: tenantId 租客ID, houseId 房源ID
* @returnboolean 是否已收藏
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:37:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean isCollected(Long tenantId, Long houseId);
/**
*
* @Function: delete
* @Description: 删除收藏(根据租客和房源)
*
* @param: tenantId 租客ID, houseId 房源ID
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:38:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean delete(Long tenantId, Long houseId);
/**
*
* @Function: deleteById
* @Description: 删除收藏根据ID
*
* @param: id 收藏ID
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:38:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean deleteById(Long id);
/**
*
* @Function: findByTenantId
* @Description: 根据租客ID查询收藏列表
*
* @param: tenantId 租客ID
* @returnList<Collection> 收藏列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:38:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<Collection> findByTenantId(Long tenantId);
/**
*
* @Function: countByTenantId
* @Description: 统计租客的收藏数量
*
* @param: tenantId 租客ID
* @returnint 收藏数量
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:38:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
int countByTenantId(Long tenantId);
}

View File

@@ -0,0 +1,307 @@
package com.hrs.dao;
import com.hrs.model.entity.House;
import java.util.List;
/**
* Copyright: Copyright (c) 2026 chinasofti
*
* @ClassName: HouseDao.java
* @Description: 房源数据层
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2026年4月13日 上午9:31:08
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2026年4月13日 赵恒 v1.0.0 新建文件
*/
public interface HouseDao {
/**
*
* @Function: findPublishedHouses
* @Description: 查询已上架的房源
*
* @param: 无
* @returnList<House> 房源列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:28:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<House> findPublishedHouses();
/**
*
* @Function: findHousesByArea
* @Description: 根据区域查询房源
*
* @param: area 区域名称
* @returnList<House> 房源列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:28:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<House> findHousesByArea(String area);
/**
*
* @Function: findHousesByPrice
* @Description: 根据价格范围查询房源
*
* @param: minPrice 最低价格, maxPrice 最高价格
* @returnList<House> 房源列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:28:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<House> findHousesByPrice(int minPrice, int maxPrice);
/**
*
* @Function: findById
* @Description: 根据ID查询房源
*
* @param: id 房源ID
* @returnHouse 房源对象未找到返回null
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:28:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
House findById(Long id);
/**
*
* @Function: findByLandlordId
* @Description: 根据房东ID查询房源
*
* @param: landlordId 房东ID
* @returnList<House> 房源列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:29:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<House> findByLandlordId(Long landlordId);
/**
*
* @Function: findAll
* @Description: 查询所有房源
*
* @param: 无
* @returnList<House> 房源列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:29:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<House> findAll();
/**
*
* @Function: findPendingHouses
* @Description: 查询待审核的房源
*
* @param: 无
* @returnList<House> 房源列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:29:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<House> findPendingHouses();
/**
*
* @Function: findPublishedHousesForAdmin
* @Description: 管理员查询已上架的房源
*
* @param: 无
* @returnList<House> 房源列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:29:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<House> findPublishedHousesForAdmin();
/**
*
* @Function: findOfflineHouses
* @Description: 查询已下架的房源
*
* @param: 无
* @returnList<House> 房源列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:30:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<House> findOfflineHouses();
/**
*
* @Function: add
* @Description: 添加房源
*
* @param: house 房源对象
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:30:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean add(House house);
/**
*
* @Function: update
* @Description: 更新房源信息
*
* @param: house 房源对象
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:30:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean update(House house);
/**
*
* @Function: updateStatus
* @Description: 更新房源状态
*
* @param: houseId 房源ID, status 状态
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:30:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean updateStatus(Long houseId, String status);
/**
*
* @Function: delete
* @Description: 删除房源
*
* @param: id 房源ID
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:31:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean delete(Long id);
/**
*
* @Function: countPublished
* @Description: 统计已上架房源数量
*
* @param: 无
* @returnint 已上架房源数量
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:31:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
int countPublished();
/**
*
* @Function: countAll
* @Description: 统计所有房源数量
*
* @param: 无
* @returnint 房源总数
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:31:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
int countAll();
}

View File

@@ -0,0 +1,250 @@
package com.hrs.dao;
import com.hrs.model.entity.Order;
import java.util.List;
/**
* Copyright: Copyright (c) 2026 chinasofti
*
* @ClassName: OrderDao.java
* @Description: 订单数据层
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2026年4月13日 上午9:31:25
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2026年4月13日 赵恒 v1.0.0 新建文件
*/
public interface OrderDao {
/**
*
* @Function: add
* @Description: 添加订单
*
* @param: order 订单对象
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:32:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean add(Order order);
/**
*
* @Function: findByTenantId
* @Description: 根据租客ID查询订单
*
* @param: tenantId 租客ID
* @returnList<Order> 订单列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:32:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<Order> findByTenantId(Long tenantId);
/**
*
* @Function: findByLandlordId
* @Description: 根据房东ID查询订单
*
* @param: landlordId 房东ID
* @returnList<Order> 订单列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:32:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<Order> findByLandlordId(Long landlordId);
/**
*
* @Function: findById
* @Description: 根据ID查询订单
*
* @param: id 订单ID
* @returnOrder 订单对象未找到返回null
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:32:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
Order findById(Long id);
/**
*
* @Function: findByOrderNo
* @Description: 根据订单编号查询订单
*
* @param: orderNo 订单编号
* @returnOrder 订单对象未找到返回null
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:33:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
Order findByOrderNo(String orderNo);
/**
*
* @Function: updateStatus
* @Description: 更新订单状态
*
* @param: orderId 订单ID, status 状态
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:33:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean updateStatus(Long orderId, String status);
/**
*
* @Function: updatePayStatus
* @Description: 更新支付状态
*
* @param: orderId 订单ID, payStatus 支付状态
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:33:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean updatePayStatus(Long orderId, String payStatus);
/**
*
* @Function: countByTenantId
* @Description: 统计租客的订单数量
*
* @param: tenantId 租客ID
* @returnint 订单数量
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:33:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
int countByTenantId(Long tenantId);
/**
*
* @Function: countByLandlordId
* @Description: 统计房东的订单数量
*
* @param: landlordId 房东ID
* @returnint 订单数量
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:34:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
int countByLandlordId(Long landlordId);
/**
*
* @Function: existsByHouseId
* @Description: 判断房源是否存在订单
*
* @param: houseId 房源ID
* @returnboolean 是否存在订单
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:34:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean existsByHouseId(Long houseId);
/**
*
* @Function: findAll
* @Description: 查询所有订单
*
* @param: 无
* @returnList<Order> 订单列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:34:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<Order> findAll();
/**
*
* @Function: countAll
* @Description: 统计所有订单数量
*
* @param: 无
* @returnint 订单总数
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:34:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
int countAll();
}

View File

@@ -0,0 +1,193 @@
package com.hrs.dao;
import com.hrs.model.entity.Reservation;
import java.util.List;
/**
* Copyright: Copyright (c) 2026 chinasofti
*
* @ClassName: ReservationDao.java
* @Description: 预约控制层
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2026年4月13日 上午9:32:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2026年4月13日 赵恒 v1.0.0 新建文件
*/
public interface ReservationDao {
/**
*
* @Function: add
* @Description: 添加预约
*
* @param: reservation 预约对象
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:35:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean add(Reservation reservation);
/**
*
* @Function: findByTenantId
* @Description: 根据租客ID查询预约
*
* @param: tenantId 租客ID
* @returnList<Reservation> 预约列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:35:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<Reservation> findByTenantId(Long tenantId);
/**
*
* @Function: findByLandlordId
* @Description: 根据房东ID查询预约
*
* @param: landlordId 房东ID
* @returnList<Reservation> 预约列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:35:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<Reservation> findByLandlordId(Long landlordId);
/**
*
* @Function: findById
* @Description: 根据ID查询预约
*
* @param: id 预约ID
* @returnReservation 预约对象未找到返回null
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:35:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
Reservation findById(Long id);
/**
*
* @Function: updateStatus
* @Description: 更新预约状态
*
* @param: id 预约ID, status 状态
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:36:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean updateStatus(Long id, String status);
/**
*
* @Function: cancel
* @Description: 取消预约
*
* @param: id 预约ID, tenantId 租客ID
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:36:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean cancel(Long id, Long tenantId);
/**
*
* @Function: countByTenantId
* @Description: 统计租客的预约数量
*
* @param: tenantId 租客ID
* @returnint 预约数量
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:36:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
int countByTenantId(Long tenantId);
/**
*
* @Function: countByLandlordId
* @Description: 统计房东的预约数量
*
* @param: landlordId 房东ID
* @returnint 预约数量
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:36:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
int countByLandlordId(Long landlordId);
/**
*
* @Function: existsByHouseId
* @Description: 判断房源是否存在预约
*
* @param: houseId 房源ID
* @returnboolean 是否存在预约
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:37:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean existsByHouseId(Long houseId);
}

View File

@@ -0,0 +1,250 @@
package com.hrs.dao;
import com.hrs.model.entity.User;
import java.util.List;
/**
* Copyright: Copyright (c) 2026 chinasofti
*
* @ClassName: UserDao.java
* @Description: 用户数据层
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2026年4月13日 上午9:32:28
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2026年4月13日 赵恒 v1.0.0 新建文件
*/
public interface UserDao {
/**
*
* @Function: findByUsernameAndPassword
* @Description: 根据用户名和密码查询用户
*
* @param: username 用户名, password 密码
* @returnUser 用户对象未找到返回null
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:25:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
User findByUsernameAndPassword(String username, String password);
/**
*
* @Function: findByUsername
* @Description: 根据用户名查询用户
*
* @param: username 用户名
* @returnUser 用户对象未找到返回null
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:25:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
User findByUsername(String username);
/**
*
* @Function: findByPhone
* @Description: 根据手机号查询用户
*
* @param: phone 手机号
* @returnUser 用户对象未找到返回null
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:25:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
User findByPhone(String phone);
/**
*
* @Function: findById
* @Description: 根据ID查询用户
*
* @param: id 用户ID
* @returnUser 用户对象未找到返回null
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:25:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
User findById(Long id);
/**
*
* @Function: findAll
* @Description: 查询所有用户
*
* @param: 无
* @returnList<User> 用户列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:26:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<User> findAll();
/**
*
* @Function: findAllTenants
* @Description: 查询所有租客
*
* @param: 无
* @returnList<User> 租客列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:26:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<User> findAllTenants();
/**
*
* @Function: findAllLandlords
* @Description: 查询所有房东
*
* @param: 无
* @returnList<User> 房东列表
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:26:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
List<User> findAllLandlords();
/**
*
* @Function: add
* @Description: 添加用户
*
* @param: user 用户对象
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:26:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean add(User user);
/**
*
* @Function: update
* @Description: 更新用户信息
*
* @param: user 用户对象
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:27:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean update(User user);
/**
*
* @Function: updateStatus
* @Description: 更新用户状态
*
* @param: userId 用户ID, status 状态
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:27:15
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean updateStatus(Long userId, String status);
/**
*
* @Function: delete
* @Description: 删除用户
*
* @param: id 用户ID
* @returnboolean 是否成功
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:27:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
boolean delete(Long id);
/**
*
* @Function: count
* @Description: 统计用户总数
*
* @param: 无
* @returnint 用户总数
* @throws
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:27:45
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
int count();
}

View File

@@ -0,0 +1,224 @@
package com.hrs.dao.impl;
import com.hrs.dao.CollectionDao;
import com.hrs.dao.HouseDao;
import com.hrs.model.entity.Collection;
import com.hrs.model.entity.House;
import com.hrs.util.DBUtil;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright: Copyright (c) 2026 chinasofti
*
* @ClassName: CollectionDaoImpl.java
* @Description: 收藏数据访问实现类
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2026年4月13日 上午9:33:33
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2026年4月13日 赵恒 v1.0.0 新建文件
*/
public class CollectionDaoImpl implements CollectionDao {
private HouseDao houseDao = new HouseDaoImpl();
/**
* 添加收藏
*/
@Override
public boolean add(Collection collection) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "INSERT INTO hrs_collection (tenant_id, house_id, collect_time, create_time) " +
"VALUES (?, ?, NOW(), NOW())";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, collection.getTenantId());
pstmt.setLong(2, collection.getHouseId());
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 检查是否已收藏
*/
@Override
public boolean isCollected(Long tenantId, Long houseId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean exists = false;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_collection WHERE tenant_id = ? AND house_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, tenantId);
pstmt.setLong(2, houseId);
rs = pstmt.executeQuery();
if (rs.next()) {
exists = rs.getInt(1) > 0;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return exists;
}
/**
* 取消收藏
*/
@Override
public boolean delete(Long tenantId, Long houseId) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "DELETE FROM hrs_collection WHERE tenant_id = ? AND house_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, tenantId);
pstmt.setLong(2, houseId);
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 根据收藏ID删除
*/
@Override
public boolean deleteById(Long id) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "DELETE FROM hrs_collection WHERE id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, id);
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 查询租客的所有收藏
*/
@Override
public List<Collection> findByTenantId(Long tenantId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<Collection> collectionList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_collection WHERE tenant_id = ? ORDER BY collect_time DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, tenantId);
rs = pstmt.executeQuery();
while (rs.next()) {
Collection collection = resultSetToCollection(rs);
// 查询关联的房源详情
House house = houseDao.findById(collection.getHouseId());
collection.setHouse(house);
collectionList.add(collection);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return collectionList;
}
/**
* 查询租客的收藏数量
*/
@Override
public int countByTenantId(Long tenantId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = 0;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_collection WHERE tenant_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, tenantId);
rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return count;
}
/**
* 将ResultSet转换为Collection对象
*/
private Collection resultSetToCollection(ResultSet rs) throws SQLException {
Collection collection = new Collection();
collection.setId(rs.getLong("id"));
collection.setTenantId(rs.getLong("tenant_id"));
collection.setHouseId(rs.getLong("house_id"));
collection.setCollectTime(rs.getTimestamp("collect_time"));
collection.setCreateBy(rs.getString("create_by"));
collection.setCreateTime(rs.getTimestamp("create_time"));
return collection;
}
}

View File

@@ -0,0 +1,548 @@
package com.hrs.dao.impl;
import com.hrs.dao.HouseDao;
import com.hrs.model.entity.House;
import com.hrs.util.DBUtil;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright: Copyright (c) 2026 chinasofti
*
* @ClassName: HouseDaoImpl.java
* @Description: 房源数据访问实现类/负责房源表的增删改查操作
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2026年4月13日 上午9:34:28
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2026年4月13日 赵恒 v1.0.0 新建文件
*/
public class HouseDaoImpl implements HouseDao {
/**
* 查询已上架的房源(供租客查看)
*/
@Override
public List<House> findPublishedHouses() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<House> houseList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT h.*, u.real_name as landlord_name, u.phone as landlord_phone " +
"FROM hrs_house h " +
"LEFT JOIN hrs_user u ON h.landlord_id = u.id " +
"WHERE h.status = '1' " +
"ORDER BY h.create_time DESC";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
houseList.add(resultSetToHouse(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return houseList;
}
/**
* 根据区域筛选房源
*/
@Override
public List<House> findHousesByArea(String area) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<House> houseList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT h.*, u.real_name as landlord_name, u.phone as landlord_phone " +
"FROM hrs_house h " +
"LEFT JOIN hrs_user u ON h.landlord_id = u.id " +
"WHERE h.status = '1' AND h.area LIKE ? " +
"ORDER BY h.create_time DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "%" + area + "%");
rs = pstmt.executeQuery();
while (rs.next()) {
houseList.add(resultSetToHouse(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return houseList;
}
/**
* 根据价格区间筛选房源
*/
@Override
public List<House> findHousesByPrice(int minPrice, int maxPrice) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<House> houseList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT h.*, u.real_name as landlord_name, u.phone as landlord_phone " +
"FROM hrs_house h " +
"LEFT JOIN hrs_user u ON h.landlord_id = u.id " +
"WHERE h.status = '1' AND h.rent_price BETWEEN ? AND ? " +
"ORDER BY h.rent_price ASC";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, minPrice);
pstmt.setInt(2, maxPrice);
rs = pstmt.executeQuery();
while (rs.next()) {
houseList.add(resultSetToHouse(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return houseList;
}
/**
* 根据房源ID查询详情
*/
@Override
public House findById(Long id) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
House house = null;
try {
conn = DBUtil.getConnection();
String sql = "SELECT h.*, u.real_name as landlord_name, u.phone as landlord_phone " +
"FROM hrs_house h " +
"LEFT JOIN hrs_user u ON h.landlord_id = u.id " +
"WHERE h.id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, id);
rs = pstmt.executeQuery();
if (rs.next()) {
house = resultSetToHouse(rs);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return house;
}
/**
* 查询房东自己的房源
*/
@Override
public List<House> findByLandlordId(Long landlordId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<House> houseList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_house WHERE landlord_id = ? ORDER BY create_time DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, landlordId);
rs = pstmt.executeQuery();
while (rs.next()) {
houseList.add(resultSetToHouse(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return houseList;
}
/**
* 查询所有房源(管理员用)
*/
@Override
public List<House> findAll() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<House> houseList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT h.*, u.real_name as landlord_name " +
"FROM hrs_house h " +
"LEFT JOIN hrs_user u ON h.landlord_id = u.id " +
"ORDER BY h.create_time DESC";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
houseList.add(resultSetToHouse(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return houseList;
}
/**
* 查询待审核房源(管理员用)
*/
@Override
public List<House> findPendingHouses() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<House> houseList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT h.*, u.real_name as landlord_name, u.phone as landlord_phone " +
"FROM hrs_house h " +
"LEFT JOIN hrs_user u ON h.landlord_id = u.id " +
"WHERE h.status = '0' " +
"ORDER BY h.create_time DESC";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
houseList.add(resultSetToHouse(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return houseList;
}
/**
* 查询已上架房源(管理员用)
*/
@Override
public List<House> findPublishedHousesForAdmin() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<House> houseList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT h.*, u.real_name as landlord_name, u.phone as landlord_phone " +
"FROM hrs_house h " +
"LEFT JOIN hrs_user u ON h.landlord_id = u.id " +
"WHERE h.status = '1' " +
"ORDER BY h.create_time DESC";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
houseList.add(resultSetToHouse(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return houseList;
}
/**
* 查询已下架房源(管理员用)
*/
@Override
public List<House> findOfflineHouses() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<House> houseList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT h.*, u.real_name as landlord_name, u.phone as landlord_phone " +
"FROM hrs_house h " +
"LEFT JOIN hrs_user u ON h.landlord_id = u.id " +
"WHERE h.status IN ('2', '3') " +
"ORDER BY h.create_time DESC";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
houseList.add(resultSetToHouse(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return houseList;
}
/**
* 添加房源
*/
@Override
public boolean add(House house) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "INSERT INTO hrs_house (landlord_id, house_no, title, area, address, " +
"house_type, rent_price, rent_type, facility, description, img_url, " +
"status, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, house.getLandlordId());
pstmt.setString(2, house.getHouseNo());
pstmt.setString(3, house.getTitle());
pstmt.setString(4, house.getArea());
pstmt.setString(5, house.getAddress());
pstmt.setString(6, house.getHouseType());
pstmt.setBigDecimal(7, house.getRentPrice());
pstmt.setString(8, house.getRentType());
pstmt.setString(9, house.getFacility());
pstmt.setString(10, house.getDescription());
pstmt.setString(11, house.getImgUrl());
pstmt.setString(12, house.getStatus() != null ? house.getStatus() : "0");
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 更新房源
*/
@Override
public boolean update(House house) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "UPDATE hrs_house SET title=?, area=?, address=?, house_type=?, " +
"rent_price=?, rent_type=?, facility=?, description=?, img_url=?, " +
"update_time=NOW() WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, house.getTitle());
pstmt.setString(2, house.getArea());
pstmt.setString(3, house.getAddress());
pstmt.setString(4, house.getHouseType());
pstmt.setBigDecimal(5, house.getRentPrice());
pstmt.setString(6, house.getRentType());
pstmt.setString(7, house.getFacility());
pstmt.setString(8, house.getDescription());
pstmt.setString(9, house.getImgUrl());
pstmt.setLong(10, house.getId());
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 更新房源状态(审核/上架/下架)
*/
@Override
public boolean updateStatus(Long houseId, String status) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "UPDATE hrs_house SET status=?, update_time=NOW() WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, status);
pstmt.setLong(2, houseId);
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 删除房源
*/
@Override
public boolean delete(Long id) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "DELETE FROM hrs_house WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, id);
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 统计已上架房源数量
*/
@Override
public int countPublished() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = 0;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_house WHERE status = '1'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return count;
}
/**
* 统计房源总数(管理员用)
*/
@Override
public int countAll() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = 0;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_house";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return count;
}
/**
* 将ResultSet转换为House对象
*/
private House resultSetToHouse(ResultSet rs) throws SQLException {
House house = new House();
house.setId(rs.getLong("id"));
house.setLandlordId(rs.getLong("landlord_id"));
house.setHouseNo(rs.getString("house_no"));
house.setTitle(rs.getString("title"));
house.setArea(rs.getString("area"));
house.setAddress(rs.getString("address"));
house.setHouseType(rs.getString("house_type"));
house.setRentPrice(rs.getBigDecimal("rent_price"));
house.setRentType(rs.getString("rent_type"));
house.setFacility(rs.getString("facility"));
house.setDescription(rs.getString("description"));
house.setImgUrl(rs.getString("img_url"));
house.setStatus(rs.getString("status"));
house.setCreateBy(rs.getString("create_by"));
house.setCreateTime(rs.getTimestamp("create_time"));
house.setUpdateBy(rs.getString("update_by"));
house.setUpdateTime(rs.getTimestamp("update_time"));
// 关联字段
try {
house.setLandlordName(rs.getString("landlord_name"));
house.setLandlordPhone(rs.getString("landlord_phone"));
} catch (SQLException e) {
// 可能没有这些字段
}
return house;
}
}

View File

@@ -0,0 +1,435 @@
package com.hrs.dao.impl;
import com.hrs.dao.HouseDao;
import com.hrs.dao.OrderDao;
import com.hrs.model.entity.House;
import com.hrs.model.entity.Order;
import com.hrs.model.entity.User;
import com.hrs.util.DBUtil;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright: Copyright (c) 2026 chinasofti
*
* @ClassName: OrderDaoImpl.java
* @Description: 订单数据访问实现类
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2026年4月13日 上午9:34:55
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2026年4月13日 赵恒 v1.0.0 新建文件
*/
public class OrderDaoImpl implements OrderDao {
private HouseDao houseDao = new HouseDaoImpl();
private UserDaoImpl userDao = new UserDaoImpl();
/**
* 添加订单
*/
@Override
public boolean add(Order order) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "INSERT INTO hrs_order (tenant_id, house_id, order_no, rent_start_time, " +
"rent_end_time, total_rent, pay_status, status, create_time) " +
"VALUES (?, ?, ?, ?, ?, ?, '0', '0', NOW())";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, order.getTenantId());
pstmt.setLong(2, order.getHouseId());
pstmt.setString(3, order.getOrderNo());
pstmt.setTimestamp(4, new Timestamp(order.getRentStartTime().getTime()));
pstmt.setTimestamp(5, new Timestamp(order.getRentEndTime().getTime()));
pstmt.setBigDecimal(6, order.getTotalRent());
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 根据租客ID查询订单列表
*/
@Override
public List<Order> findByTenantId(Long tenantId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<Order> orderList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_order WHERE tenant_id = ? ORDER BY create_time DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, tenantId);
rs = pstmt.executeQuery();
while (rs.next()) {
Order order = resultSetToOrder(rs);
orderList.add(order);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return orderList;
}
/**
* 根据房东ID查询订单列表
*/
@Override
public List<Order> findByLandlordId(Long landlordId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<Order> orderList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT o.* FROM hrs_order o " +
"INNER JOIN hrs_house h ON o.house_id = h.id " +
"WHERE h.landlord_id = ? " +
"ORDER BY o.create_time DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, landlordId);
rs = pstmt.executeQuery();
while (rs.next()) {
Order order = resultSetToOrder(rs);
orderList.add(order);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return orderList;
}
/**
* 根据订单ID查询
*/
@Override
public Order findById(Long id) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Order order = null;
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_order WHERE id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, id);
rs = pstmt.executeQuery();
if (rs.next()) {
order = resultSetToOrder(rs);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return order;
}
/**
* 根据订单编号查询
*/
@Override
public Order findByOrderNo(String orderNo) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Order order = null;
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_order WHERE order_no = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, orderNo);
rs = pstmt.executeQuery();
if (rs.next()) {
order = resultSetToOrder(rs);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return order;
}
/**
* 更新订单状态
*/
@Override
public boolean updateStatus(Long orderId, String status) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "UPDATE hrs_order SET status=?, update_time=NOW() WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, status);
pstmt.setLong(2, orderId);
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 更新支付状态
*/
@Override
public boolean updatePayStatus(Long orderId, String payStatus) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "UPDATE hrs_order SET pay_status=?, update_time=NOW() WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, payStatus);
pstmt.setLong(2, orderId);
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 统计租客订单数量
*/
@Override
public int countByTenantId(Long tenantId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = 0;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_order WHERE tenant_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, tenantId);
rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return count;
}
/**
* 统计房东订单数量
*/
@Override
public int countByLandlordId(Long landlordId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = 0;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_order o " +
"INNER JOIN hrs_house h ON o.house_id = h.id " +
"WHERE h.landlord_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, landlordId);
rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return count;
}
/**
* 检查房源是否存在关联订单
*/
@Override
public boolean existsByHouseId(Long houseId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_order WHERE house_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, houseId);
rs = pstmt.executeQuery();
if (rs.next()) {
return rs.getInt(1) > 0;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return false;
}
/**
* 查询所有订单(管理员用)
*/
@Override
public List<Order> findAll() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<Order> orderList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT o.* FROM hrs_order o " +
"ORDER BY o.create_time DESC";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
Order order = resultSetToOrder(rs);
orderList.add(order);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return orderList;
}
/**
* 统计所有订单数量(管理员用)
*/
@Override
public int countAll() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = 0;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_order";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return count;
}
/**
* 将ResultSet转换为Order对象
*/
private Order resultSetToOrder(ResultSet rs) throws SQLException {
Order order = new Order();
order.setId(rs.getLong("id"));
order.setTenantId(rs.getLong("tenant_id"));
order.setHouseId(rs.getLong("house_id"));
order.setOrderNo(rs.getString("order_no"));
order.setRentStartTime(rs.getTimestamp("rent_start_time"));
order.setRentEndTime(rs.getTimestamp("rent_end_time"));
order.setTotalRent(rs.getBigDecimal("total_rent"));
order.setPayStatus(rs.getString("pay_status"));
order.setStatus(rs.getString("status"));
order.setCreateBy(rs.getString("create_by"));
order.setCreateTime(rs.getTimestamp("create_time"));
order.setUpdateBy(rs.getString("update_by"));
order.setUpdateTime(rs.getTimestamp("update_time"));
try {
House house = houseDao.findById(order.getHouseId());
order.setHouse(house);
} catch (Exception e) {
// 忽略
}
try {
User tenant = userDao.findById(order.getTenantId());
order.setTenant(tenant);
} catch (Exception e) {
// 忽略
}
return order;
}
}

View File

@@ -0,0 +1,338 @@
package com.hrs.dao.impl;
import com.hrs.dao.HouseDao;
import com.hrs.dao.ReservationDao;
import com.hrs.dao.UserDao;
import com.hrs.model.entity.Reservation;
import com.hrs.model.entity.House;
import com.hrs.model.entity.User;
import com.hrs.util.DBUtil;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright: Copyright (c) 2026 chinasofti
*
* @ClassName: ReservationDaoImpl.java
* @Description: 预约看房数据访问实现类
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2026年4月13日 上午9:35:10
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2026年4月13日 赵恒 v1.0.0 新建文件
*/
public class ReservationDaoImpl implements ReservationDao {
private HouseDao houseDao = new HouseDaoImpl();
private UserDao userDao = new UserDaoImpl();
/**
* 添加预约
*/
@Override
public boolean add(Reservation reservation) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "INSERT INTO hrs_reservation (tenant_id, house_id, landlord_id, reserve_time, remark, status, create_time) " +
"VALUES (?, ?, ?, ?, ?, '0', NOW())";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, reservation.getTenantId());
pstmt.setLong(2, reservation.getHouseId());
pstmt.setLong(3, reservation.getLandlordId());
pstmt.setTimestamp(4, new Timestamp(reservation.getReserveTime().getTime()));
pstmt.setString(5, reservation.getRemark());
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 查询租客的所有预约
*/
@Override
public List<Reservation> findByTenantId(Long tenantId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<Reservation> reservationList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_reservation WHERE tenant_id = ? ORDER BY reserve_time DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, tenantId);
rs = pstmt.executeQuery();
while (rs.next()) {
Reservation reservation = resultSetToReservation(rs);
// 关联房源详情
House house = houseDao.findById(reservation.getHouseId());
reservation.setHouse(house);
reservationList.add(reservation);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return reservationList;
}
/**
* 查询房东收到的预约
*/
@Override
public List<Reservation> findByLandlordId(Long landlordId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<Reservation> reservationList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_reservation WHERE landlord_id = ? ORDER BY reserve_time DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, landlordId);
rs = pstmt.executeQuery();
while (rs.next()) {
Reservation reservation = resultSetToReservation(rs);
// 关联房源详情
House house = houseDao.findById(reservation.getHouseId());
reservation.setHouse(house);
// 关联租客信息
User tenant = userDao.findById(reservation.getTenantId());
reservation.setTenant(tenant);
reservationList.add(reservation);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return reservationList;
}
/**
* 根据ID查询预约
*/
@Override
public Reservation findById(Long id) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Reservation reservation = null;
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_reservation WHERE id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, id);
rs = pstmt.executeQuery();
if (rs.next()) {
reservation = resultSetToReservation(rs);
House house = houseDao.findById(reservation.getHouseId());
reservation.setHouse(house);
User tenant = userDao.findById(reservation.getTenantId());
reservation.setTenant(tenant);
User landlord = userDao.findById(reservation.getLandlordId());
reservation.setLandlord(landlord);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return reservation;
}
/**
* 更新预约状态(房东确认/取消)
*/
@Override
public boolean updateStatus(Long id, String status) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "UPDATE hrs_reservation SET status=?, handle_time=NOW(), update_time=NOW() WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, status);
pstmt.setLong(2, id);
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 取消预约(租客取消)
*/
@Override
public boolean cancel(Long id, Long tenantId) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "UPDATE hrs_reservation SET status='2', update_time=NOW() WHERE id=? AND tenant_id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, id);
pstmt.setLong(2, tenantId);
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
* 统计租客的预约数量
*/
@Override
public int countByTenantId(Long tenantId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = 0;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_reservation WHERE tenant_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, tenantId);
rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return count;
}
/**
* 统计房东的预约数量
*/
@Override
public int countByLandlordId(Long landlordId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = 0;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_reservation WHERE landlord_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, landlordId);
rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return count;
}
/**
* 检查房源是否存在关联预约
*/
@Override
public boolean existsByHouseId(Long houseId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_reservation WHERE house_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, houseId);
rs = pstmt.executeQuery();
if (rs.next()) {
return rs.getInt(1) > 0;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return false;
}
/**
* 将ResultSet转换为Reservation对象
*/
private Reservation resultSetToReservation(ResultSet rs) throws SQLException {
Reservation reservation = new Reservation();
reservation.setId(rs.getLong("id"));
reservation.setTenantId(rs.getLong("tenant_id"));
reservation.setHouseId(rs.getLong("house_id"));
reservation.setLandlordId(rs.getLong("landlord_id"));
reservation.setReserveTime(rs.getTimestamp("reserve_time"));
reservation.setRemark(rs.getString("remark"));
reservation.setStatus(rs.getString("status"));
reservation.setHandleTime(rs.getTimestamp("handle_time"));
reservation.setCreateBy(rs.getString("create_by"));
reservation.setCreateTime(rs.getTimestamp("create_time"));
reservation.setUpdateBy(rs.getString("update_by"));
reservation.setUpdateTime(rs.getTimestamp("update_time"));
return reservation;
}
}

View File

@@ -0,0 +1,602 @@
package com.hrs.dao.impl;
import com.hrs.dao.UserDao;
import com.hrs.model.entity.User;
import com.hrs.util.DBUtil;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright: Copyright (c) 2026 chinasofti
*
* @ClassName: UserDaoImpl.java
* @Description: 用户数据访问实现类/负责用户表的增删改查操作
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2026年4月13日 上午9:35:47
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2026年4月13日 赵恒 v1.0.0 新建文件
*/
public class UserDaoImpl implements UserDao {
/**
*
* @Function: findByUsernameAndPassword
* @Description: 根据用户名和密码查询用户(登录用)
*
* @param: username 用户名, password 密码
* @returnUser 用户对象未找到返回null
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:40:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public User findByUsernameAndPassword(String username, String password) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
User user = null;
try {
// 1. 获取连接
conn = DBUtil.getConnection();
// 2. 编写SQL注意实际项目密码应该是加密后比较这里简化
String sql = "SELECT * FROM hrs_user WHERE user_name = ? AND password = ?";
// 3. 创建预编译语句
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, username);
pstmt.setString(2, password); // 实际应该是MD5加密后比较
// 4. 执行查询
rs = pstmt.executeQuery();
// 5. 处理结果集
if (rs.next()) {
user = resultSetToUser(rs);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 6. 释放资源
DBUtil.close(rs, pstmt, conn);
}
return user;
}
/**
*
* @Function: findByUsername
* @Description: 根据用户名查询用户(检查用户名是否已存在)
*
* @param: username 用户名
* @returnUser 用户对象未找到返回null
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:40:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public User findByUsername(String username) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
User user = null;
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_user WHERE user_name = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, username);
rs = pstmt.executeQuery();
if (rs.next()) {
user = resultSetToUser(rs);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return user;
}
/**
*
* @Function: findByPhone
* @Description: 根据手机号查询用户(检查手机号是否已注册)
*
* @param: phone 手机号
* @returnUser 用户对象未找到返回null
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:41:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public User findByPhone(String phone) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
User user = null;
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_user WHERE phone = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, phone);
rs = pstmt.executeQuery();
if (rs.next()) {
user = resultSetToUser(rs);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return user;
}
/**
*
* @Function: findById
* @Description: 根据ID查询用户
*
* @param: id 用户ID
* @returnUser 用户对象未找到返回null
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:41:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public User findById(Long id) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
User user = null;
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_user WHERE id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, id);
rs = pstmt.executeQuery();
if (rs.next()) {
user = resultSetToUser(rs);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return user;
}
/**
*
* @Function: findAll
* @Description: 查询所有用户(管理员用)
*
* @param: 无
* @returnList<User> 用户列表
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:42:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public List<User> findAll() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<User> userList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_user ORDER BY create_time DESC";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
userList.add(resultSetToUser(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return userList;
}
/**
*
* @Function: findAllTenants
* @Description: 查询所有租客
*
* @param: 无
* @returnList<User> 租客列表
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:42:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public List<User> findAllTenants() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<User> userList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_user WHERE role_type = '0' ORDER BY create_time DESC";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
userList.add(resultSetToUser(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return userList;
}
/**
*
* @Function: findAllLandlords
* @Description: 查询所有房东
*
* @param: 无
* @returnList<User> 房东列表
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:43:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public List<User> findAllLandlords() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<User> userList = new ArrayList<>();
try {
conn = DBUtil.getConnection();
String sql = "SELECT * FROM hrs_user WHERE role_type = '1' ORDER BY create_time DESC";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
userList.add(resultSetToUser(rs));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return userList;
}
/**
*
* @Function: add
* @Description: 添加用户(注册用)
*
* @param: user 用户对象
* @returnboolean 是否成功
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:43:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public boolean add(User user) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "INSERT INTO hrs_user (user_name, password, real_name, phone, id_card, role_type, status, create_time) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, NOW())";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, user.getUserName());
pstmt.setString(2, user.getPassword());
pstmt.setString(3, user.getRealName());
pstmt.setString(4, user.getPhone());
pstmt.setString(5, user.getIdCard());
pstmt.setString(6, user.getRoleType());
pstmt.setString(7, user.getStatus() != null ? user.getStatus() : "0"); // 默认未认证
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
*
* @Function: update
* @Description: 更新用户信息
*
* @param: user 用户对象
* @returnboolean 是否成功
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:44:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public boolean update(User user) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "UPDATE hrs_user SET real_name=?, phone=?, id_card=?, status=?, update_time=NOW() WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, user.getRealName());
pstmt.setString(2, user.getPhone());
pstmt.setString(3, user.getIdCard());
pstmt.setString(4, user.getStatus());
pstmt.setLong(5, user.getId());
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
*
* @Function: updateStatus
* @Description: 更新用户状态(启用/禁用)
*
* @param: userId 用户ID, status 状态
* @returnboolean 是否成功
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:44:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public boolean updateStatus(Long userId, String status) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "UPDATE hrs_user SET status=?, update_time=NOW() WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, status);
pstmt.setLong(2, userId);
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
*
* @Function: delete
* @Description: 删除用户(物理删除,一般不建议)
*
* @param: id 用户ID
* @returnboolean 是否成功
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:45:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public boolean delete(Long id) {
Connection conn = null;
PreparedStatement pstmt = null;
boolean success = false;
try {
conn = DBUtil.getConnection();
String sql = "DELETE FROM hrs_user WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, id);
int rows = pstmt.executeUpdate();
success = rows > 0;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, conn);
}
return success;
}
/**
*
* @Function: count
* @Description: 统计用户总数
*
* @param: 无
* @returnint 用户总数
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:45:30
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
@Override
public int count() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = 0;
try {
conn = DBUtil.getConnection();
String sql = "SELECT COUNT(*) FROM hrs_user";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, conn);
}
return count;
}
/**
*
* @Function: resultSetToUser
* @Description: 将ResultSet转换为User对象
*
* @param: rs 结果集
* @returnUser 用户对象
* @throwsSQLException
*
* @version: v1.0.0
* @author: 赵恒
* @date: 2025年4月13日 下午3:46:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2025年4月13日 赵恒 v1.0.0 新建方法
*/
private User resultSetToUser(ResultSet rs) throws SQLException {
User user = new User();
user.setId(rs.getLong("id"));
user.setUserName(rs.getString("user_name"));
user.setPassword(rs.getString("password"));
user.setRealName(rs.getString("real_name"));
user.setPhone(rs.getString("phone"));
user.setIdCard(rs.getString("id_card"));
user.setRoleType(rs.getString("role_type"));
user.setStatus(rs.getString("status"));
user.setCreateBy(rs.getString("create_by"));
user.setCreateTime(rs.getTimestamp("create_time"));
user.setUpdateBy(rs.getString("update_by"));
user.setUpdateTime(rs.getTimestamp("update_time"));
return user;
}
}