From fb798e4982a392408b3e8324c69baba0824fe3fd Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Fri, 03 Nov 2023 13:44:15 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
src/main/java/org/springblade/modules/house/service/impl/HouseRentalServiceImpl.java | 124 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 124 insertions(+), 0 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..71195c3 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,8 +16,11 @@
*/
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.house.entity.HouseRentalEntity;
+import org.springblade.modules.house.entity.HouseTenantEntity;
import org.springblade.modules.house.service.IHouseTenantService;
import org.springblade.modules.house.vo.HouseRentalVO;
import org.springblade.modules.house.mapper.HouseRentalMapper;
@@ -27,8 +30,13 @@
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.Iterator;
import java.util.List;
+import java.util.stream.Collectors;
/**
* 出租屋 服务实现类
@@ -64,4 +72,120 @@
// 返回
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;
+ }
}
--
Gitblit v1.9.3