尚庭公寓-----day2 业务功能实现
公寓信息管理
需要实现六个接口
- 根据id修改公寓发布状态
controller
层
@Operation(summary = "根据id修改公寓发布状态")@PostMapping("updateReleaseStatusById")public Result updateReleaseStatusById(@RequestParam Long id, @RequestParam ReleaseStatus status) {LambdaUpdateWrapper<ApartmentInfo> updateWrapper = new LambdaUpdateWrapper<>();updateWrapper.eq(ApartmentInfo::getId,id);updateWrapper.set(ApartmentInfo::getIsRelease,status);apartmentInfoService.update(updateWrapper);return Result.ok();}
- 保存或更新公寓信息
controller
层
import java.util.List;@Tag(name = "公寓信息管理")
@RestController
@RequestMapping("/admin/apartment")
public class ApartmentController {@Autowiredprivate ApartmentInfoService apartmentInfoService;@Operation(summary = "保存或更新公寓信息")@PostMapping("saveOrUpdate")public Result saveOrUpdate(@RequestBody ApartmentSubmitVo apartmentSubmitVo) {apartmentInfoService.saveOrUpdateApartment(apartmentSubmitVo);return Result.ok();}
service
层
package com.nie.lease.web.admin.service;import com.nie.lease.model.entity.ApartmentInfo;
import com.nie.lease.web.admin.vo.apartment.ApartmentDetailVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentItemVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentQueryVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentSubmitVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;/**
* @author liubo
* @description 针对表【apartment_info(公寓信息表)】的数据库操作Service
* @createDate 2023-07-24 15:48:00
*/
public interface ApartmentInfoService extends IService<ApartmentInfo> {void saveOrUpdateApartment(ApartmentSubmitVo apartmentSubmitVo);
}
service
实现类
package com.nie.lease.web.admin.service.impl;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nie.lease.common.exception.LeaseException;
import com.nie.lease.common.result.ResultCodeEnum;
import com.nie.lease.model.entity.*;
import com.nie.lease.model.enums.ItemType;
import com.nie.lease.web.admin.mapper.*;
import com.nie.lease.web.admin.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nie.lease.web.admin.vo.apartment.ApartmentDetailVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentItemVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentQueryVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentSubmitVo;
import com.nie.lease.web.admin.vo.fee.FeeValueVo;
import com.nie.lease.web.admin.vo.graph.GraphVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;import java.util.ArrayList;
import java.util.List;/*** @author liubo* @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现* @createDate 2023-07-24 15:48:00*/
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>implements ApartmentInfoService {@Autowiredprivate GraphInfoService graphInfoService;@Autowiredprivate ApartmentFacilityService apartmentFacilityService;@Autowiredprivate ApartmentLabelService apartmentLabelService;@Autowiredprivate ApartmentFeeValueService apartmentFeeValueService;@Autowiredprivate ApartmentInfoMapper apartmentInfoMapper;@Autowiredprivate GraphInfoMapper graphInfoMapper;@Autowiredprivate LabelInfoMapper labelInfoMapper;@Autowiredprivate FacilityInfoMapper facilityInfoMapper;@Autowiredprivate FeeValueMapper feeValueMapper;@Autowiredprivate RoomInfoMapper roomInfoMapper;@Overridepublic void saveOrUpdateApartment(ApartmentSubmitVo apartmentSubmitVo) {boolean IsUpdate=apartmentSubmitVo.getId()!=null;super.saveOrUpdate(apartmentSubmitVo);if (IsUpdate) {//删除图片列表LambdaUpdateWrapper<GraphInfo> graphInfoLambdaUpdateWrapper = new LambdaUpdateWrapper<>();graphInfoLambdaUpdateWrapper.eq(GraphInfo::getItemType, ItemType.APARTMENT);graphInfoLambdaUpdateWrapper.eq(GraphInfo::getItemId,apartmentSubmitVo.getId());graphInfoService.remove(graphInfoLambdaUpdateWrapper);//删除配套列表LambdaUpdateWrapper<ApartmentFacility> apartmentFacilityLambdaUpdateWrapper = new LambdaUpdateWrapper<>();apartmentFacilityLambdaUpdateWrapper.eq(ApartmentFacility::getApartmentId,apartmentSubmitVo.getId());apartmentFacilityService.remove(apartmentFacilityLambdaUpdateWrapper);//删除标签列表LambdaUpdateWrapper<ApartmentLabel> apartmentLabelLambdaUpdateWrapper = new LambdaUpdateWrapper<>();apartmentLabelLambdaUpdateWrapper.eq(ApartmentLabel::getApartmentId,apartmentSubmitVo.getId());apartmentLabelService.remove(apartmentLabelLambdaUpdateWrapper);//删除杂费列表LambdaUpdateWrapper<ApartmentFeeValue> apartmentFeeValueLambdaUpdateWrapper = new LambdaUpdateWrapper<>();apartmentFeeValueLambdaUpdateWrapper.eq(ApartmentFeeValue::getApartmentId,apartmentSubmitVo.getId());apartmentFeeValueService.remove(apartmentFeeValueLambdaUpdateWrapper);}//插入图片列表List<GraphVo> graphVoList = apartmentSubmitVo.getGraphVoList();if (!CollectionUtils.isEmpty(graphVoList)){ArrayList<GraphInfo> graphInfoList = new ArrayList<>();for (GraphVo graphVo : graphVoList) {GraphInfo graphInfo = new GraphInfo();graphInfo.setItemType(ItemType.APARTMENT);graphInfo.setItemId(apartmentSubmitVo.getId());graphInfo.setName(graphVo.getName());graphInfo.setUrl(graphVo.getUrl());graphInfoList.add(graphInfo);}graphInfoService.saveBatch(graphInfoList);}//插入配套列表List<Long> facilityInfoIdList = apartmentSubmitVo.getFacilityInfoIds();if (!CollectionUtils.isEmpty(facilityInfoIdList)){ArrayList<ApartmentFacility> facilityList = new ArrayList<>();for (Long facilityId : facilityInfoIdList) {ApartmentFacility apartmentFacility = new ApartmentFacility();apartmentFacility.setApartmentId(apartmentSubmitVo.getId());apartmentFacility.setFacilityId(facilityId);facilityList.add(apartmentFacility);}apartmentFacilityService.saveBatch(facilityList);}//插入标签列表List<Long> labelIds = apartmentSubmitVo.getLabelIds();if (!CollectionUtils.isEmpty(labelIds)) {List<ApartmentLabel> apartmentLabelList = new ArrayList<>();for (Long labelId : labelIds) {ApartmentLabel apartmentLabel = new ApartmentLabel();apartmentLabel.setApartmentId(apartmentSubmitVo.getId());apartmentLabel.setLabelId(labelId);apartmentLabelList.add(apartmentLabel);}apartmentLabelService.saveBatch(apartmentLabelList);}//插入杂费列表List<Long> feeValueIds = apartmentSubmitVo.getFeeValueIds();if (!CollectionUtils.isEmpty(feeValueIds)) {ArrayList<ApartmentFeeValue> apartmentFeeValueList = new ArrayList<>();for (Long feeValueId : feeValueIds) {ApartmentFeeValue apartmentFeeValue = new ApartmentFeeValue();apartmentFeeValue.setApartmentId(apartmentSubmitVo.getId());apartmentFeeValue.setFeeValueId(feeValueId);apartmentFeeValueList.add(apartmentFeeValue);}apartmentFeeValueService.saveBatch(apartmentFeeValueList);}}
- 根据条件分页查询公寓列表
controller
层
@Operation(summary = "根据条件分页查询公寓列表")@GetMapping("pageItem")public Result<IPage<ApartmentItemVo>> pageItem(@RequestParam long current, @RequestParam long size, ApartmentQueryVo queryVo) {Page<ApartmentItemVo> page = new Page<>(current, size);IPage<ApartmentItemVo> result=apartmentInfoService.pageItem(page, queryVo);return Result.ok(result);}
service
接口
IPage<ApartmentItemVo> pageItem(Page<ApartmentItemVo> page, ApartmentQueryVo queryVo);
service
实现类
@Overridepublic IPage<ApartmentItemVo> pageItem(Page<ApartmentItemVo> page, ApartmentQueryVo queryVo) {return apartmentInfoMapper.pageItem(page, queryVo);}
mapper
接口
package com.nie.lease.web.admin.mapper;import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nie.lease.model.entity.ApartmentInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nie.lease.web.admin.vo.apartment.ApartmentItemVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentQueryVo;/**
* @author liubo
* @description 针对表【apartment_info(公寓信息表)】的数据库操作Mapper
* @createDate 2023-07-24 15:48:00
* @Entity com.nie.lease.model.ApartmentInfo
*/
public interface ApartmentInfoMapper extends BaseMapper<ApartmentInfo> {IPage<ApartmentItemVo> pageItem(Page<ApartmentItemVo> page, ApartmentQueryVo queryVo);
}
mapper
实现
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nie.lease.web.admin.mapper.ApartmentInfoMapper"><select id="pageItem" resultType="com.nie.lease.web.admin.vo.apartment.ApartmentItemVo">select ai.id,ai.name,ai.introduction,ai.district_id,ai.district_name,ai.city_id,ai.city_name,ai.province_id,ai.province_name,ai.address_detail,ai.latitude,ai.longitude,ai.phone,ai.is_release,ifnull(tc.cnt,0) total_room_count,ifnull(tc.cnt,0) - ifnull(cc.cnt,0) free_room_countfrom (select id,name,introduction,district_id,district_name,city_id,city_name,province_id,province_name,address_detail,latitude,longitude,phone,is_releasefrom apartment_info<where>is_deleted=0<if test="queryVo.provinceId !=null">and province_id=#{queryVo.provinceId}</if><if test="queryVo.cityId !=null">and city_id=#{queryVo.cityId}</if><if test="queryVo.districtId !=null">and district_id=#{queryVo.districtId}</if></where>) aileft join(select apartment_id,COUNT(*) cntfrom room_infowhere is_deleted = 0and is_release = 1group by apartment_id) tcon ai.id = tc.apartment_idleft join(select apartment_id,COUNT(*) cntfrom lease_agreementwhere is_deleted = 0and status in (2, 5)group by apartment_id) ccon ai.id = cc.apartment_id</select>
</mapper>
- 根据区县id查询公寓信息列表
controller
层
@Operation(summary = "根据区县id查询公寓信息列表")@GetMapping("listInfoByDistrictId")public Result<List<ApartmentInfo>> listInfoByDistrictId(@RequestParam Long id) {LambdaQueryWrapper<ApartmentInfo> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.eq(ApartmentInfo::getDistrictId,id);List<ApartmentInfo> list = apartmentInfoService.list(queryWrapper);return Result.ok(list);}
service
接口
package com.nie.lease.web.admin.service;import com.nie.lease.model.entity.ApartmentInfo;
import com.nie.lease.web.admin.vo.apartment.ApartmentDetailVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentItemVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentQueryVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentSubmitVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;/**
* @author liubo
* @description 针对表【apartment_info(公寓信息表)】的数据库操作Service
* @createDate 2023-07-24 15:48:00
*/
public interface ApartmentInfoService extends IService<ApartmentInfo> {void saveOrUpdateApartment(ApartmentSubmitVo apartmentSubmitVo);IPage<ApartmentItemVo> pageItem(Page<ApartmentItemVo> page, ApartmentQueryVo queryVo);ApartmentDetailVo getDetailById(Long id);void removeApartmentById(Long id);
}
- 根据ID获取公寓详细信息
controller
层
@Operation(summary = "根据ID获取公寓详细信息")@GetMapping("getDetailById")public Result<ApartmentDetailVo> getDetailById(@RequestParam Long id) {ApartmentDetailVo result=apartmentInfoService.getDetailById(id);return Result.ok(result);}
service
接口
package com.nie.lease.web.admin.service;import com.nie.lease.model.entity.ApartmentInfo;
import com.nie.lease.web.admin.vo.apartment.ApartmentDetailVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentItemVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentQueryVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentSubmitVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;/**
* @author liubo
* @description 针对表【apartment_info(公寓信息表)】的数据库操作Service
* @createDate 2023-07-24 15:48:00
*/
public interface ApartmentInfoService extends IService<ApartmentInfo> {void saveOrUpdateApartment(ApartmentSubmitVo apartmentSubmitVo);IPage<ApartmentItemVo> pageItem(Page<ApartmentItemVo> page, ApartmentQueryVo queryVo);ApartmentDetailVo getDetailById(Long id);void removeApartmentById(Long id);
}
service
实现类
public ApartmentDetailVo getDetailById(Long id) {//查询公寓信息ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(id);//查询图片列表List<GraphVo> graphVoList=graphInfoMapper.selectListByItemTypeAndItemId(ItemType.APARTMENT,id);//查询标签列表List<LabelInfo> labelInfoList=labelInfoMapper.selectListByApartmentId(id);//查询配套列表List<FacilityInfo> facilityInfoList=facilityInfoMapper.selectListByApartmentId(id);//查询杂费列表List<FeeValueVo> feeValueVoList=feeValueMapper.selectListByApartmentId(id);//组装VOApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();BeanUtils.copyProperties(apartmentInfo, apartmentDetailVo);apartmentDetailVo.setGraphVoList(graphVoList);apartmentDetailVo.setLabelInfoList(labelInfoList);apartmentDetailVo.setFacilityInfoList(facilityInfoList);apartmentDetailVo.setFeeValueVoList(feeValueVoList);return apartmentDetailVo;}
mapper
接口
package com.nie.lease.web.admin.mapper;import com.nie.lease.model.entity.GraphInfo;
import com.nie.lease.model.enums.ItemType;
import com.nie.lease.web.admin.vo.graph.GraphVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;import java.util.List;/**
* @author liubo
* @description 针对表【graph_info(图片信息表)】的数据库操作Mapper
* @createDate 2023-07-24 15:48:00
* @Entity com.atguigu.lease.model.GraphInfo
*/
public interface GraphInfoMapper extends BaseMapper<GraphInfo> {List<GraphVo> selectListByItemTypeAndItemId(ItemType itemType, Long id);
}
package com.nie.lease.web.admin.mapper;import com.nie.lease.model.entity.LabelInfo;
import com.nie.lease.model.enums.ItemType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;import java.util.List;/**
* @author liubo
* @description 针对表【label_info(标签信息表)】的数据库操作Mapper
* @createDate 2023-07-24 15:48:00
* @Entity com.atguigu.lease.model.LabelInfo
*/
public interface LabelInfoMapper extends BaseMapper<LabelInfo> {List<LabelInfo> selectListByApartmentId(Long id);
}
package com.nie.lease.web.admin.mapper;import com.nie.lease.model.entity.LabelInfo;
import com.nie.lease.model.enums.ItemType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;import java.util.List;/**
* @author liubo
* @description 针对表【label_info(标签信息表)】的数据库操作Mapper
* @createDate 2023-07-24 15:48:00
* @Entity com.atguigu.lease.model.LabelInfo
*/
public interface LabelInfoMapper extends BaseMapper<LabelInfo> {List<LabelInfo> selectListByApartmentId(Long id);
}
package com.nie.lease.web.admin.mapper;import com.nie.lease.model.entity.FacilityInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;import java.util.List;/**
* @author liubo
* @description 针对表【facility_info(配套信息表)】的数据库操作Mapper
* @createDate 2023-07-24 15:48:00
* @Entity com.atguigu.lease.model.FacilityInfo
*/
public interface FacilityInfoMapper extends BaseMapper<FacilityInfo> {List<FacilityInfo> selectListByApartmentId(Long id);
}
package com.nie.lease.web.admin.mapper;import com.nie.lease.model.entity.FeeValue;
import com.nie.lease.web.admin.vo.fee.FeeValueVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;import java.util.List;/**
* @author liubo
* @description 针对表【fee_value(杂项费用值表)】的数据库操作Mapper
* @createDate 2023-07-24 15:48:00
* @Entity com.atguigu.lease.model.FeeValue
*/
public interface FeeValueMapper extends BaseMapper<FeeValue> {List<FeeValueVo> selectListByApartmentId(Long id);
}
mapper
实现类
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nie.lease.web.admin.mapper.LabelInfoMapper"><select id="selectListByApartmentId" resultType="com.nie.lease.model.entity.LabelInfo">select id,type,namefrom label_infowhere is_deleted = 0and id in (select label_idfrom apartment_labelwhere is_deleted = 0and apartment_id = #{id})</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nie.lease.web.admin.mapper.GraphInfoMapper"><select id="selectListByItemTypeAndItemId" resultType="com.nie.lease.web.admin.vo.graph.GraphVo">selectname,urlfrom graph_infowhere is_deleted=0and item_type=#{itemType}and item_id=#{id}</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nie.lease.web.admin.mapper.LabelInfoMapper"><select id="selectListByApartmentId" resultType="com.nie.lease.model.entity.LabelInfo">select id,type,namefrom label_infowhere is_deleted = 0and id in (select label_idfrom apartment_labelwhere is_deleted = 0and apartment_id = #{id})</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nie.lease.web.admin.mapper.FacilityInfoMapper"><select id="selectListByApartmentId" resultType="com.nie.lease.model.entity.FacilityInfo">select id,type,name,iconfrom facility_infowhere is_deleted = 0and id in (select facility_idfrom apartment_facilitywhere is_deleted = 0and apartment_id = #{id})</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nie.lease.web.admin.mapper.FeeValueMapper"><select id="selectListByApartmentId" resultType="com.nie.lease.web.admin.vo.fee.FeeValueVo">select fv.id,fv.name,fv.unit,fv.fee_key_id,fk.id,fk.name fee_key_namefrom fee_value fvjoin fee_key fk on fv.fee_key_id = fk.idwhere fk.is_deleted = 0and fv.is_deleted = 0and fv.id in (select fee_value_idfrom apartment_fee_valuewhere is_deleted = 0and apartment_id = #{id})</select>
</mapper>
- 根据id删除公寓信息
controller
层
@Operation(summary = "根据id删除公寓信息")@DeleteMapping("removeById")public Result removeById(@RequestParam Long id) {apartmentInfoService.removeApartmentById(id);return Result.ok();}
service
接口
package com.nie.lease.web.admin.service;import com.nie.lease.model.entity.ApartmentInfo;
import com.nie.lease.web.admin.vo.apartment.ApartmentDetailVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentItemVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentQueryVo;
import com.nie.lease.web.admin.vo.apartment.ApartmentSubmitVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;/**
* @author liubo
* @description 针对表【apartment_info(公寓信息表)】的数据库操作Service
* @createDate 2023-07-24 15:48:00
*/
public interface ApartmentInfoService extends IService<ApartmentInfo> {void removeApartmentById(Long id);
}
service
实现类
public void removeApartmentById(Long id) {LambdaQueryWrapper<RoomInfo> roomQueryWrapper = new LambdaQueryWrapper<>();roomQueryWrapper.eq(RoomInfo::getApartmentId,id);Long count = roomInfoMapper.selectCount(roomQueryWrapper);if (count>0){//有房间,不能删除throw new LeaseException(ResultCodeEnum.ADMIN_APARTMENT_DELETE_ERROR);}super.removeById(id);//删除图片列表LambdaUpdateWrapper<GraphInfo> graphInfoLambdaUpdateWrapper = new LambdaUpdateWrapper<>();graphInfoLambdaUpdateWrapper.eq(GraphInfo::getItemType, ItemType.APARTMENT);graphInfoLambdaUpdateWrapper.eq(GraphInfo::getItemId,id);graphInfoService.remove(graphInfoLambdaUpdateWrapper);//删除配套列表LambdaUpdateWrapper<ApartmentFacility> apartmentFacilityLambdaUpdateWrapper = new LambdaUpdateWrapper<>();apartmentFacilityLambdaUpdateWrapper.eq(ApartmentFacility::getApartmentId,id);apartmentFacilityService.remove(apartmentFacilityLambdaUpdateWrapper);//删除标签列表LambdaUpdateWrapper<ApartmentLabel> apartmentLabelLambdaUpdateWrapper = new LambdaUpdateWrapper<>();apartmentLabelLambdaUpdateWrapper.eq(ApartmentLabel::getApartmentId,id);apartmentLabelService.remove(apartmentLabelLambdaUpdateWrapper);//删除杂费列表LambdaUpdateWrapper<ApartmentFeeValue> apartmentFeeValueLambdaUpdateWrapper = new LambdaUpdateWrapper<>();apartmentFeeValueLambdaUpdateWrapper.eq(ApartmentFeeValue::getApartmentId,id);apartmentFeeValueService.remove(apartmentFeeValueLambdaUpdateWrapper);}
定义异常处理类
package com.nie.lease.common.exception;import com.nie.lease.common.result.ResultCodeEnum;
import lombok.Data;
import org.springframework.context.annotation.Configuration;@Data
public class LeaseException extends RuntimeException{private Integer code;public LeaseException(Integer code,String message){super(message);this.code=code;}public LeaseException(ResultCodeEnum resultCodeEnum){super(resultCodeEnum.getMessage());this.code=resultCodeEnum.getCode();}
}
package com.nie.lease.common.exception;import com.nie.lease.common.result.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;@ControllerAdvice
public class GlobalExceptionHandler {@ExceptionHandler(Exception.class)@ResponseBodypublic Result handle(Exception e){e.printStackTrace();return Result.fail();}@ExceptionHandler(LeaseException.class)@ResponseBodypublic Result handle(LeaseException e){e.printStackTrace();return Result.fail(e.getCode(),e.getMessage());}}