预约看房接口说明:ViewAppointmentController
@Tag(name = "预约看房管理")
@RequestMapping("/admin/appointment")
@RestController
public class ViewAppointmentController {
@Autowired
private ViewAppointmentService service;
}
一、分页查询预约信息接口
接口名称:page
请求方式:Get
请求路径:/admin/appointment/page
请求参数:@RequestParam long current,
@RequestParam long size,
AppointmentQueryVo queryVo
返回类型:IPage<AppointmentVo>
由于返回的类型为Vo对象,所以需要我们自定义分页查询方法。
controller层:
返回的Vo对象:AppointmentVo。继承了ViewAppointment,需要查询ViewAppointment的信息去连接ApartmentInfo的表去获取信息,最后存储进入ApointmentInfo的对象进行返回。
@Data
@Schema(description = "预约看房信息")
public class AppointmentVo extends ViewAppointment {
@Schema(description = "预约公寓信息")
private ApartmentInfo apartmentInfo;
}
@Operation(summary = "分页查询预约信息")
@GetMapping("page")
public Result<IPage<AppointmentVo>> page(@RequestParam long current, @RequestParam long size, AppointmentQueryVo queryVo) {
IPage<AppointmentVo> page = new Page<>(current,size);
IPage<AppointmentVo> result=service.pageAppointment(page,queryVo);
return Result.ok(result);
}
service层:
@Autowired
private ViewAppointmentMapper viewAppointmentMapper;
@Override
public IPage<AppointmentVo> pageAppointment(IPage<AppointmentVo> page, AppointmentQueryVo queryVo) {
return viewAppointmentMapper.pageAppointment(page,queryVo);
}
mapper层:
<resultMap id="AppointmentVoMap" type="com.atguigu.lease.web.admin.vo.appointment.AppointmentVo" autoMapping="true">
<id property="id" column="id"/>
<association property="apartmentInfo" javaType="com.atguigu.lease.model.entity.ApartmentInfo" autoMapping="true">
<id property="id" column="apartment_id"/>
<result property="name" column="apartment_name"/>
<result property="phone" column="apartment_phone"/>
</association>
</resultMap>
<select id="pageAppointment" resultMap="AppointmentVoMap">
select va.id,
va.user_id,
va.name,
va.phone,
va.appointment_time,
va.additional_info,
va.appointment_status,
ai.id apartment_id,
ai.name apartment_name,
ai.district_id,
ai.district_name,
ai.city_id,
ai.city_name,
ai.province_id,
ai.province_name,
ai.phone apartment_phone
from view_appointment va
left join
apartment_info ai
on va.apartment_id = ai.id and ai.is_deleted=0
<where>
va.is_deleted = 0
<if test="queryVo.provinceId != null">
and ai.province_id = #{queryVo.provinceId}
</if>
<if test="queryVo.cityId != null">
and ai.city_id = #{queryVo.cityId}
</if>
<if test="queryVo.districtId != null">
and ai.district_id = #{queryVo.districtId}
</if>
<if test="queryVo.apartmentId != null">
and va.apartment_id = #{queryVo.apartmentId}
</if>
<if test="queryVo.name != null and queryVo.name != ''">
and va.name like concat('%',#{queryVo.name},'%')
</if>
<if test="queryVo.phone != null and queryVo.phone != ''">
and va.phone like concat('%',#{queryVo.phone},'%')
</if>
</where>
</select>
二、根据id更新预约状态接口
接口名称:updateStatusById
请求方式:Post
请求路径:/admin/appointment/updateStatusById
请求参数:@RequestParam Long id,
@RequestParam AppointmentStatus status
返回类型:Result
controller层:
@Operation(summary = "根据id更新预约状态")
@PostMapping("updateStatusById")
public Result updateStatusById(@RequestParam Long id, @RequestParam AppointmentStatus status) {
LambdaUpdateWrapper<ViewAppointment> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(ViewAppointment::getId,id);
updateWrapper.set(ViewAppointment::getAppointmentStatus,status);
service.update(updateWrapper);
return Result.ok();
}
租约管理接口说明:LeaseAgreementController
@Tag(name = "租约管理")
@RestController
@RequestMapping("/admin/agreement")
public class LeaseAgreementController {
@Autowired
private LeaseAgreementService service;
}
一、保存或修改租约信息接口
接口名称:saveOrUpdate
请求方式:Post
请求路径:/admin/appointment/saveOrUpdate
请求参数:@RequestBody LeaseAgreement leaseAgreement
返回类型:Result
cotroller层:
由于请求参数为普通的实体类,我们直接调用MybatisPlus提供的Service方法即可。
@Autowired
private LeaseAgreementService service;
@Operation(summary = "保存或修改租约信息")
@PostMapping("saveOrUpdate")
public Result saveOrUpdate(@RequestBody LeaseAgreement leaseAgreement) {
service.saveOrUpdate(leaseAgreement);
return Result.ok();
}
二、根据条件分页查询租约列表接口
接口名称:page
请求方式:Get
请求路径:/admin/agreement/page
请求参数:@RequestParam long current,
@RequestParam long size,
AgreementQueryVo queryVo
返回类型:IPage<AgreementVo>
controller层:
仍然为返回Vo对象,需要自己定义分页方法pageAgreement()。
@Operation(summary = "根据条件分页查询租约列表")
@GetMapping("page")
public Result<IPage<AgreementVo>> page(@RequestParam long current, @RequestParam long size, AgreementQueryVo queryVo) {
IPage<AgreementVo> page = new Page<>(current,size);
IPage<AgreementVo> result = service.pageAgreement(page,queryVo);
return Result.ok(result);
}
service层:
@Override
public IPage<AgreementVo> pageAgreement(IPage<AgreementVo> page, AgreementQueryVo queryVo) {
return leaseAgreementMapper.pageAgreement(page,queryVo);
}
mapper层:
<resultMap id="agreementVoMap" type="com.atguigu.lease.web.admin.vo.agreement.AgreementVo" autoMapping="true">
<id property="id" column="id"/>
<association property="apartmentInfo" javaType="com.atguigu.lease.model.entity.ApartmentInfo" autoMapping="true">
<id property="id" column="apartment_id"/>
<result property="name" column="apartment_name"/>
</association>
<association property="roomInfo" javaType="com.atguigu.lease.model.entity.RoomInfo" autoMapping="true">
<id property="id" column="room_id"/>
</association>
<association property="paymentType" javaType="com.atguigu.lease.model.entity.PaymentType" autoMapping="true">
<id property="id" column="payment_type_id"/>
<result property="name" column="payment_type_name"/>
</association>
<association property="leaseTerm" javaType="com.atguigu.lease.model.entity.LeaseTerm" autoMapping="true">
<id property="id" column="lease_term_id"/>
</association>
</resultMap>
<select id="pageAgreement" resultMap="agreementVoMap">
select la.id,
la.phone,
la.name,
la.identification_number,
la.lease_start_date,
la.lease_end_date,
la.rent,
la.deposit,
la.status,
la.source_type,
la.additional_info,
ai.id apartment_id,
ai.name apartment_name,
ai.district_id,
ai.district_name,
ai.city_id,
ai.city_name,
ai.province_id,
ai.province_name,
ri.id room_id,
ri.room_number,
pt.id payment_type_id,
pt.name payment_type_name,
pt.pay_month_count,
lt.id lease_term_id,
lt.month_count,
lt.unit
from lease_agreement la
left join
apartment_info ai
on la.apartment_id = ai.id and ai.is_deleted=0
left join
room_info ri
on la.room_id = ri.id and ri.is_deleted=0
left join
payment_type pt
on la.payment_type_id = pt.id and pt.is_deleted=0
left join
lease_term lt
on la.lease_term_id = lt.id and lt.is_deleted=0
<where>
la.is_deleted = 0
<if test="queryVo.provinceId != null">
and ai.province_id = #{queryVo.provinceId}
</if>
<if test="queryVo.cityId != null">
and ai.city_id = #{queryVo.cityId}
</if>
<if test="queryVo.districtId != null">
and ai.district_id = #{queryVo.districtId}
</if>
<if test="queryVo.apartmentId != null">
and la.apartment_id = #{queryVo.apartmentId}
</if>
<if test="queryVo.roomNumber != null and queryVo.roomNumber != ''">
and ri.room_number like concat('%',#{queryVo.roomNumber},'%')
</if>
<if test="queryVo.name != null and queryVo.name != ''">
and la.name like concat('%',#{queryVo.name},'%')
</if>
<if test="queryVo.phone != null and queryVo.phone != ''">
and la.phone like concat('%',#{queryVo.phone},'%')
</if>
</where>
</select>
三、根据id查询租约信息接口
接口名称:getById
请求方式:Get
请求路径:/admin/agreement/getById
请求参数:@RequestParam Long id
返回类型:AgreementVo
controller层:
返回值为AgreementVo类型的对象,需要自定义查询方法。
@Operation(summary = "根据id查询租约信息")
@GetMapping(name = "getById")
public Result<AgreementVo> getById(@RequestParam Long id) {
AgreementVo result=service.getAgreementById(id);
return Result.ok(result);
}
service层:
注入LeaseAgreement的mapper,通过id查询leaseAgreement对象获取Vo对象所需的公寓信息、支付方式、租期信息、房间信息。最后创建Vo对象,把查询到的数据插入对象中,最后返回。
@Override
public AgreementVo getAgreementById(Long id) {
LeaseAgreement leaseAgreement = leaseAgreementMapper.selectById(id);
ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(leaseAgreement.getApartmentId());
PaymentType paymentType = paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId());
LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseAgreement.getLeaseTermId());
RoomInfo roomInfo = roomInfoMapper.selectById(leaseAgreement.getRoomId());
AgreementVo agreementVo = new AgreementVo();
agreementVo.setLeaseTerm(leaseTerm);
agreementVo.setPaymentType(paymentType);
agreementVo.setApartmentInfo(apartmentInfo);
agreementVo.setRoomInfo(roomInfo);
return agreementVo;
}
四、根据id删除租约信息
接口名称:removeById
请求方式:Delete
请求路径:/admin/agreement/removeById
请求参数:@RequestParam Long id
返回类型:Result
controller层:
@Operation(summary = "根据id删除租约信息")
@DeleteMapping("removeById")
public Result removeById(@RequestParam Long id) {
service.removeById(id);
return Result.ok();
}
五、根据id更新租约状态接口
接口名称:updateStatusById
请求方式:Post
请求路径:/admin/agreement/updateStatusById
请求参数:@RequestParam Long id,
@RequestParam LeaseStatus status
返回类型:Result
controller层:
使用条件查询更新。
@Operation(summary = "根据id更新租约状态")
@PostMapping("updateStatusById")
public Result updateStatusById(@RequestParam Long id, @RequestParam LeaseStatus status) {
LambdaUpdateWrapper<LeaseAgreement> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(LeaseAgreement::getId,id);
updateWrapper.set(LeaseAgreement::getStatus,status);
service.update(updateWrapper);
return Result.ok();
}
997

被折叠的 条评论
为什么被折叠?



