From 5d5cd3ad979a0b85ab8c7034dcad1663fdcf71be Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Fri, 01 Dec 2023 14:18:53 +0800
Subject: [PATCH] 文章通过范围查询
---
src/main/java/org/springblade/modules/house/service/impl/HouseRentalServiceImpl.java | 195 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 192 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/springblade/modules/house/service/impl/HouseRentalServiceImpl.java b/src/main/java/org/springblade/modules/house/service/impl/HouseRentalServiceImpl.java
index 44bda12..1e02036 100644
--- a/src/main/java/org/springblade/modules/house/service/impl/HouseRentalServiceImpl.java
+++ b/src/main/java/org/springblade/modules/house/service/impl/HouseRentalServiceImpl.java
@@ -16,19 +16,29 @@
*/
package org.springblade.modules.house.service.impl;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.modules.grid.service.IGridService;
import org.springblade.modules.house.entity.HouseRentalEntity;
+import org.springblade.modules.house.entity.HouseTenantEntity;
import org.springblade.modules.house.service.IHouseTenantService;
+import org.springblade.modules.house.vo.HouseRentalStatistics;
+import org.springblade.modules.house.vo.HouseRentalTenantVO;
import org.springblade.modules.house.vo.HouseRentalVO;
import org.springblade.modules.house.mapper.HouseRentalMapper;
import org.springblade.modules.house.service.IHouseRentalService;
-import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.modules.house.vo.HouseTenantVO;
+import org.springblade.modules.house.excel.HouseRentalExcel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springframework.transaction.annotation.Transactional;
+import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import java.util.stream.Collectors;
/**
* 出租屋 服务实现类
@@ -42,6 +52,9 @@
@Autowired
private IHouseTenantService houseTenantService;
+ @Autowired
+ private IGridService gridService;
+
/**
* 自定义分页查询
* @param page
@@ -49,8 +62,20 @@
* @return
*/
@Override
- public IPage<HouseRentalVO> selectHouseRentalPage(IPage<HouseRentalVO> page, HouseRentalVO houseRental) {
- return page.setRecords(baseMapper.selectHouseRentalPage(page, houseRental));
+ public IPage<HouseRentalTenantVO> selectHouseRentalPage(IPage<HouseRentalTenantVO> page, HouseRentalTenantVO houseRental) {
+ List<String> list = new ArrayList<>();
+ if (null!=houseRental.getRoleName() && !houseRental.getRoleName().equals("")){
+ if (houseRental.getRoleName().equals("网格员")){
+ // 查询对应的房屋地址code
+ list = gridService.getAddressCodeListByUserId(AuthUtil.getUserId());
+ }
+ }
+ if (null!=houseRental.getAuditStatus()){
+ if (houseRental.getAuditStatus()==0){
+ houseRental.setAuditStatus(2);
+ }
+ }
+ return page.setRecords(baseMapper.selectHouseRentalPage(page, houseRental,list));
}
/**
@@ -64,4 +89,168 @@
// 返回
return houseRentalVOS;
}
+
+ /**
+ * 自定义房屋出租新增
+ * @param houseRentalVO
+ * @return
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Boolean add(HouseRentalVO houseRentalVO) {
+ houseRentalVO.setCreateUser(AuthUtil.getUserId());
+ houseRentalVO.setCreateTime(new Date());
+ houseRentalVO.setUpdateUser(AuthUtil.getUserId());
+ houseRentalVO.setUpdateTime(new Date());
+ //保存自身
+ boolean save = save(houseRentalVO);
+ List<HouseTenantEntity> houseTenantEntities = new ArrayList<>();
+ houseRentalVO.getHouseTenantVOList().forEach(e->{
+ HouseTenantEntity houseTenant= new HouseTenantEntity();
+
+ houseTenant.setHousingRentalId(houseRentalVO.getId());
+ houseTenant.setName(e.getName());
+ houseTenant.setPhone(e.getPhone());
+ houseTenant.setIdCard(e.getIdCard());
+ houseTenant.setDomicile(e.getDomicile());
+ houseTenant.setWorkUnit(e.getWorkUnit());
+ houseTenantEntities.add(houseTenant);
+
+ });
+ boolean saveBatch = houseTenantService.saveBatch(houseTenantEntities);
+
+ return save&&saveBatch;
+ }
+
+ /**
+ * 出租屋 自定义删除
+ * @param id
+ * @return
+ */
+ @Override
+ public Boolean removeHouseRental(Long id) {
+ // 先删除出租屋信息
+ boolean b = removeById(id);
+ // 再删除租户信息
+ int i = houseTenantService.removeByHousingRentalId(id);
+ if (i>0){
+ return true && b;
+ }
+ return false;
+ }
+
+ /**
+ * 出租屋 自定义修改
+ * @param houseRental
+ * @return
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Boolean updateHouseRental(HouseRentalVO houseRental) {
+ boolean addFlag = true;
+ boolean updateFlag = true;
+ boolean removeFlag = true;
+ houseRental.setUpdateUser(AuthUtil.getUserId());
+ houseRental.setUpdateTime(new Date());
+ //更新自身
+ boolean update = updateById(houseRental);
+ // 查询对应已存在的租户
+ QueryWrapper<HouseTenantEntity> wrapper = new QueryWrapper<>();
+ wrapper.eq("housing_rental_id",houseRental.getId());
+ List<HouseTenantEntity> oldList = houseTenantService.list(wrapper);
+ List<HouseTenantVO> list = houseRental.getHouseTenantVOList();
+ // 申明新增,修改,删除集合
+ List<HouseTenantEntity> newList = new ArrayList<>();
+ List<HouseTenantEntity> addList = new ArrayList<>();
+ List<HouseTenantEntity> updateList = new ArrayList<>();
+ List<HouseTenantEntity> removeList = new ArrayList<>();
+ // 找出需要新增的,否则组成新集合进行比对
+ for (HouseTenantVO houseTenantVO : list) {
+ houseTenantVO.setHousingRentalId(houseRental.getId());
+ if (null==houseTenantVO.getId()){
+ // 新增
+ HouseTenantEntity houseTenant= new HouseTenantEntity();
+
+ houseTenant.setHousingRentalId(houseRental.getId());
+ houseTenant.setName(houseTenantVO.getName());
+ houseTenant.setPhone(houseTenantVO.getPhone());
+ houseTenant.setIdCard(houseTenantVO.getIdCard());
+ houseTenant.setDomicile(houseTenantVO.getDomicile());
+ houseTenant.setWorkUnit(houseTenantVO.getWorkUnit());
+ addList.add(houseTenant);
+ }else {
+ newList.add(houseTenantVO);
+ }
+ }
+ // 遍历去差集,判断是新增还是删除还是更新
+ // 取旧数据和新提交数据差集--删除
+ removeList = oldList.stream().filter(vo -> !newList.stream().map(e ->
+ e.getId()).collect(Collectors.toList()).contains(vo.getId())).collect(Collectors.toList());
+ // 取旧数据和新提交数据交集--更新
+ updateList = newList.stream().filter(vo -> oldList.stream().map(e ->
+ e.getId()).collect(Collectors.toList()).contains(vo.getId())).collect(Collectors.toList());
+
+ // 批量新增
+ if (addList.size()>0) {
+ addFlag = houseTenantService.saveBatch(addList);
+ }
+ // 批量修改
+ if (updateList.size()>0) {
+ updateFlag = houseTenantService.updateBatchById(updateList);
+ }
+ // 批量删除
+ if (removeList.size()>0) {
+ removeFlag = houseTenantService.removeBatchByIds(removeList);
+ }
+ // 返回
+ return update && addFlag && updateFlag && removeFlag;
+ }
+
+ /**
+ * 获取统计数据
+ * @return
+ */
+ @Override
+ public Object getStatistics(HouseRentalTenantVO houseRental) {
+ List<String> list = new ArrayList<>();
+ if (null!=houseRental.getRoleName() && !houseRental.getRoleName().equals("")){
+ if (houseRental.getRoleName().equals("网格员")){
+ // 查询对应的房屋地址code
+ list = gridService.getAddressCodeListByUserId(AuthUtil.getUserId());
+ }
+ }
+ // 查询
+ List<HouseRentalStatistics> statistics = baseMapper.getStatistics(houseRental,list);
+ // 返回
+ return statistics;
+ }
+
+ /**
+ * 出租屋 确认
+ * @param houseRental
+ * @return
+ */
+ @Override
+ public Boolean confirmHouseRental(HouseRentalVO houseRental) {
+ // 修改状态
+ houseRental.setUpdateTime(new Date());
+ // 修改
+ return updateById(houseRental);
+ }
+
+ /**
+ * 导出租赁信息
+ * @param houseRentalVO
+ * @return
+ */
+ @Override
+ public List<HouseRentalExcel> export(HouseRentalTenantVO houseRentalVO) {
+ List<HouseRentalExcel> houseRentalExcels = baseMapper.export(houseRentalVO);
+ return houseRentalExcels;
+ }
+
+ @Override
+ public Integer getStatisticsCount(HouseRentalTenantVO houseRental) {
+ return baseMapper.getStatisticsCount(AuthUtil.getUserId());
+ }
}
--
Gitblit v1.9.3