package com.atguigu.lease.web.admin.service.impl;
import com.atguigu.lease.common.exception.LeaseException;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.mapper.RoomInfoMapper;
import com.atguigu.lease.web.admin.service.*;
import com.atguigu.lease.web.admin.vo.attr.AttrValueVo;
import com.atguigu.lease.web.admin.vo.graph.GraphVo;
import com.atguigu.lease.web.admin.vo.room.RoomDetailVo;
import com.atguigu.lease.web.admin.vo.room.RoomItemVo;
import com.atguigu.lease.web.admin.vo.room.RoomQueryVo;
import com.atguigu.lease.web.admin.vo.room.RoomSubmitVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
/**
* @author liubo
* @description 针对表【room_info(房间信息表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class RoomInfoServiceImpl extends ServiceImpl<RoomInfoMapper, RoomInfo>
implements RoomInfoService {
@Autowired
private GraphInfoService graphInfoService;
@Autowired
private RoomAttrValueService roomAttrValueService;
@Autowired
private RoomFacilityService roomFacilityService;
@Autowired
private RoomLabelService roomLabelService;
@Autowired
private RoomPaymentTypeService roomPaymentTypeService;
@Autowired
private RoomLeaseTermService roomLeaseTermService;
@Lazy
@Autowired
private LeaseAgreementService leaseAgreementService;
@Autowired
private RoomInfoMapper roomInfoMapper;
@Lazy
@Autowired
private ApartmentInfoService apartmentInfoService;
@Autowired
private FacilityInfoService facilityInfoService;
@Autowired
private LabelInfoService labelInfoService;
/**
* @Description: 先看看lease_agreement里面有没有租约(租约状态是2 , 5),没有租约再删除房间
* @Param: [id]
* @return: void
* @Author: simonf
* @Date: 2024/1/24
*/
@Override
public void customRemoveRoomById(Long id) {
//先看看lease_agreement里面有没有租约(租约状态是2,5)
// 1.看看房间里面有没有租约,(多表关联查询,根据传入的id查询Lease_Agreement表里的room_id)
LambdaQueryWrapper<LeaseAgreement> leaseAgreementIfNull = new LambdaQueryWrapper<>();
leaseAgreementIfNull.eq(LeaseAgreement::getRoomId, id);
Long count = leaseAgreementService.count(leaseAgreementIfNull);
if (count > 0) {
// 2.看看租约状态
LambdaQueryWrapper<LeaseAgreement> leaseAgreementQueryWrapper = new LambdaQueryWrapper<>();
leaseAgreementQueryWrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING);
List<LeaseAgreement> list = leaseAgreementService.list(leaseAgreementQueryWrapper);
//3.如果租约还有且状态为(2,5)抛异常
System.out.println(list+"这是租约相关对象");
if (!list.isEmpty()) {
throw new LeaseException(ResultCodeEnum.DELETE_ERROR);
}
}
//1.删除RoomInfo
super.removeById(id);
//2.删除graphInfoList
LambdaQueryWrapper<GraphInfo> graphQueryWrapper = new LambdaQueryWrapper<>();
graphQueryWrapper.eq(GraphInfo::getItemType, ItemType.ROOM);
graphQueryWrapper.eq(GraphInfo::getItemId, id);
graphInfoService.remove(graphQueryWrapper);
//3.删除attrValueList
LambdaQueryWrapper<RoomAttrValue> attrQueryWrapper = new LambdaQueryWrapper<>();
attrQueryWrapper.eq(RoomAttrValue::getRoomId, id);
roomAttrValueService.remove(attrQueryWrapper);
//4.删除facilityInfoList
LambdaQueryWrapper<RoomFacility> facilityQueryWrapper = new LambdaQueryWrapper<>();
facilityQueryWrapper.eq(RoomFacility::getRoomId, id);
roomFacilityService.remove(facilityQueryWrapper);
//5.删除labelInfoList
LambdaQueryWrapper<RoomLabel> labelQueryWrapper = new LambdaQueryWrapper<>();
labelQueryWrapper.eq(RoomLabel::getRoomId, id);
roomLabelService.remove(labelQueryWrapper);
//6.删除paymentTypeList
LambdaQueryWrapper<RoomPaymentType> paymentQueryWrapper = new LambdaQueryWrapper<>();
paymentQueryWrapper.eq(RoomPaymentType::getRoomId, id);
roomPaymentTypeService.remove(paymentQueryWrapper);
//7.删除leaseTermList
LambdaQueryWrapper<RoomLeaseTerm> termQueryWrapper = new LambdaQueryWrapper<>();
termQueryWrapper.eq(RoomLeaseTerm::getRoomId, id);
roomLeaseTermService.remove(termQueryWrapper);
}
@Override
public void saveOrUpdateRoom(RoomSubmitVo roomSubmitVo) {
boolean isUpdate = roomSubmitVo.getId() != null;
super.saveOrUpdate(roomSubmitVo);
//若为更新操作,则先删除与Room相关的各项信息列表
if (isUpdate) {
//1.删除原有graphInfoList
LambdaQueryWrapper<GraphInfo> graphQueryWrapper = new LambdaQueryWrapper<>();
graphQueryWrapper.eq(GraphInfo::getItemType, ItemType.ROOM);
graphQueryWrapper.eq(GraphInfo::getItemId, roomSubmitVo.getId());
graphInfoService.remove(graphQueryWrapper);
//2.删除原有roomAttrValueList
LambdaQueryWrapper<RoomAttrValue> attrQueryMapper = new LambdaQueryWrapper<>();
attrQueryMapper.eq(RoomAttrValue::getRoomId, roomSubmitVo.getId());
roomAttrValueService.remove(attrQueryMapper);
//3.删除原有roomFacilityList
LambdaQueryWrapper<RoomFacility> facilityQueryWrapper = new LambdaQueryWrapper<>();
facilityQueryWrapper.eq(RoomFacility::getRoomId, roomSubmitVo.getId());
roomFacilityService.remove(facilityQueryWrapper);
//4.删除原有roomLabelList
LambdaQueryWrapper<RoomLabel> labelQueryWrapper = new LambdaQueryWrapper<>();
labelQueryWrapper.eq(RoomLabel::getRoomId, roomSubmitVo.getId());
roomLabelService.remove(labelQueryWrapper);
//5.删除原有paymentTypeList
LambdaQueryWrapper<RoomPaymentType> paymentQueryWrapper = new LambdaQueryWrapper<>();
paymentQueryWrapper.eq(RoomPaymentType::getRoomId, roomSubmitVo.getId());
roomPaymentTypeService.remove(paymentQueryWrapper);
//6.删除原有leaseTermList
LambdaQueryWrapper<RoomLeaseTerm> termQueryWrapper = new LambdaQueryWrapper<>();
termQueryWrapper.eq(RoomLeaseTerm::getRoomId, roomSubmitVo.getId());
roomLeaseTermService.remove(termQueryWrapper);
}
//1.保存新的graphInfoList
List<GraphVo> graphVoList = roomSubmitVo.getGraphVoList();
if (!CollectionUtils.isEmpty(graphVoList)) {
ArrayList<GraphInfo> graphInfoList = new ArrayList<>();
for (GraphVo graphVo : graphVoList) {
GraphInfo graphInfo = new GraphInfo();
graphInfo.setItemType(ItemType.ROOM);
graphInfo.setItemId(roomSubmitVo.getId());
graphInfo.setName(graphVo.getName());
graphInfo.setUrl(graphVo.getUrl());
graphInfoList.add(graphInfo);
}
graphInfoService.saveBatch(graphInfoList);
}
//2.保存新的
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
尚庭公寓租赁平台 - 基于Java开发,包含367个文件,如JAVA、XML、YML、LICENSE、MD和GITIGNORE等。该平台为用户提供找房、看房预约、租约管理等功能,同时为管理员提供公寓(房源)管理、租赁管理、用户管理等功能,是一个完整的公寓租赁解决方案。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的尚庭公寓租赁平台设计源码 (367个子文件)
.gitignore 351B
RoomInfoServiceImpl.java 12KB
ApartmentInfoServiceImpl.java 10KB
RoomInfoServiceImpl.java 5KB
LoginServiceImpl.java 5KB
LoginServiceImpl.java 5KB
ApartmentInfoServiceImpl.java 4KB
SystemUserController.java 4KB
Knife4jConfiguration.java 3KB
ApartmentController.java 3KB
LeaseAgreementServiceImpl.java 3KB
RoomController.java 3KB
Knife4jConfiguration.java 3KB
LeaseAgreementController.java 3KB
LeaseAgreementServiceImpl.java 3KB
SystemPostController.java 3KB
RegionInfoController.java 2KB
LeaseAgreementController.java 2KB
RegionController.java 2KB
AttrController.java 2KB
BrowsingHistoryServiceImpl.java 2KB
LeaseAgreement.java 2KB
FeeController.java 2KB
SystemUserServiceImpl.java 2KB
FileServiceImpl.java 2KB
UserInfoController.java 2KB
LoginController.java 2KB
RoomController.java 2KB
ViewAppointmentServiceImpl.java 2KB
ApartmentInfo.java 2KB
FacilityController.java 2KB
LabelController.java 2KB
ViewAppointmentController.java 2KB
SystemUser.java 2KB
ResultCodeEnum.java 2KB
PaymentTypeController.java 2KB
RedisConfiguration.java 2KB
JwtUtil.java 2KB
WebMvcConfiguration.java 1KB
AuthenticationInterceptor.java 1KB
AuthenticationInterceptor.java 1KB
LeaseTermController.java 1KB
ViewAppointmentController.java 1KB
BrowsingHistoryController.java 1KB
WebMvcConfiguration.java 1KB
RoomDetailVo.java 1KB
LoginController.java 1KB
PaymentTypeController.java 1KB
AgreementItemVo.java 1KB
ViewAppointment.java 1KB
Result.java 1KB
AliyunSMSConfiguration.java 1KB
LeaseException.java 1KB
ScheduledTask.java 1KB
GraphInfoServiceImpl.java 1KB
PaymentTypeServiceImpl.java 1KB
ViewAppointmentServiceImpl.java 1KB
LeaseTermServiceImpl.java 1KB
LeaseTermController.java 1KB
ApartmentController.java 1KB
RoomAttrValueServiceImpl.java 1KB
UserInfo.java 1KB
ApartmentFacilityServiceImpl.java 1KB
ApartmentFeeValueServiceImpl.java 1KB
FacilityInfoServiceImpl.java 1KB
ApartmentLabelServiceImpl.java 1KB
RoomLeaseTermServiceImpl.java 1KB
ApartmentInfoMapper.java 1KB
RoomDetailVo.java 1KB
LabelInfoServiceImpl.java 1KB
GraphInfoServiceImpl.java 1024B
RoomPaymentTypeServiceImpl.java 1024B
FileUploadController.java 1015B
ApartmentInfoService.java 1012B
RoomInfo.java 982B
HistoryItemVo.java 973B
RoomInfoMapper.java 972B
SystemUserMapper.java 961B
FeeValueServiceImpl.java 958B
StringToBaseEnumConverterFactory.java 956B
StringToBaseEnumConverterFactory.java 954B
AttrValueServiceImpl.java 950B
RoomItemVo.java 946B
RoomInfoService.java 944B
AgreementDetailVo.java 936B
FacilityInfoServiceImpl.java 930B
BrowsingHistory.java 928B
ApartmentDetailVo.java 919B
RoomInfoService.java 916B
SystemPost.java 901B
BaseEntity.java 897B
AttrKeyServiceImpl.java 892B
FeeKeyServiceImpl.java 891B
LabelInfoServiceImpl.java 891B
AppointmentItemVo.java 881B
GraphInfo.java 878B
ViewAppointmentMapper.java 862B
ApartmentDetailVo.java 859B
RoomSubmitVo.java 853B
MybatisPlusConfiguration.java 789B
共 367 条
- 1
- 2
- 3
- 4
资源评论
沐知全栈开发
- 粉丝: 5703
- 资源: 5219
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功