| | |
| | | package org.springblade.modules.house.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springblade.common.utils.SpringUtils; |
| | | 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.entity.HouseholdEntity; |
| | | import org.springblade.modules.house.excel.HouseRentalExcel; |
| | | import org.springblade.modules.house.mapper.HouseRentalMapper; |
| | | import org.springblade.modules.house.service.IHouseRentalService; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | 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.modules.house.vo.HouseTenantVO; |
| | | import org.springblade.modules.house.excel.HouseRentalExcel; |
| | | import org.springblade.modules.house.vo.HouseholdVO; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.service.IUserService; |
| | | 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; |
| | |
| | | public class HouseRentalServiceImpl extends ServiceImpl<HouseRentalMapper, HouseRentalEntity> implements IHouseRentalService { |
| | | |
| | | @Autowired |
| | | private IHouseTenantService houseTenantService; |
| | | private IHouseholdService iHouseholdService; |
| | | |
| | | |
| | | @Autowired |
| | | private IGridService gridService; |
| | |
| | | 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); |
| | | |
| | | List<String> phoneList = new ArrayList<>(); |
| | | List<HouseholdEntity> householdEntityList = new ArrayList<>(); |
| | | houseRentalVO.getHouseholdVOList().forEach(e -> { |
| | | e.setHouseCode(houseRentalVO.getHouseCode()); |
| | | e.setHousingRentalId(houseRentalVO.getId()); |
| | | e.setRelationship(18); |
| | | e.setResidentialStatus(1); |
| | | e.setRoleType(2); |
| | | householdEntityList.add(e); |
| | | phoneList.add(e.getPhoneNumber()); |
| | | }); |
| | | boolean saveBatch = houseTenantService.saveBatch(houseTenantEntities); |
| | | try { |
| | | // 查询租户是否网格员身份的,给网格员设置居民角色 |
| | | IUserService bean = SpringUtils.getBean(IUserService.class); |
| | | String str = "1717429261910528001"; |
| | | List<User> list = bean.list(Wrappers.<User>lambdaQuery() |
| | | .in(User::getPhone, phoneList) |
| | | .like(User::getRoleId, str)); |
| | | for (User user : list) { |
| | | boolean contains = user.getRoleId().contains("1717429059648606209"); |
| | | if (contains) { |
| | | continue; |
| | | } |
| | | user.setRoleId(user.getRoleId() + ",1717429059648606209"); |
| | | } |
| | | bean.updateBatchById(list); |
| | | } catch (Exception e) { |
| | | log.error("保存用户角色为居民:", e); |
| | | } |
| | | boolean saveBatch = iHouseholdService.saveBatch(householdEntityList); |
| | | |
| | | return save&&saveBatch; |
| | | return save && saveBatch; |
| | | } |
| | | |
| | | /** |
| | |
| | | // 先删除出租屋信息 |
| | | boolean b = removeById(id); |
| | | // 再删除租户信息 |
| | | int i = houseTenantService.removeByHousingRentalId(id); |
| | | if (i>0){ |
| | | boolean update = iHouseholdService.update(Wrappers.<HouseholdEntity>lambdaUpdate() |
| | | .set(HouseholdEntity::getIsDeleted, 1) |
| | | .eq(HouseholdEntity::getHousingRentalId, id)); |
| | | if (update) { |
| | | return true && b; |
| | | } |
| | | return false; |
| | |
| | | //更新自身 |
| | | 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(); |
| | | QueryWrapper<HouseholdEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("housing_rental_id", houseRental.getId()); |
| | | List<HouseholdEntity> oldList = iHouseholdService.list(wrapper); |
| | | List<HouseholdVO> list = houseRental.getHouseholdVOList(); |
| | | // 申明新增,修改,删除集合 |
| | | List<HouseTenantEntity> newList = new ArrayList<>(); |
| | | List<HouseTenantEntity> addList = new ArrayList<>(); |
| | | List<HouseTenantEntity> updateList = new ArrayList<>(); |
| | | List<HouseTenantEntity> removeList = new ArrayList<>(); |
| | | List<HouseholdEntity> newList = new ArrayList<>(); |
| | | List<HouseholdEntity> addList = new ArrayList<>(); |
| | | List<HouseholdEntity> updateList = new ArrayList<>(); |
| | | List<HouseholdEntity> removeList = new ArrayList<>(); |
| | | // 找出需要新增的,否则组成新集合进行比对 |
| | | for (HouseTenantVO houseTenantVO : list) { |
| | | houseTenantVO.setHousingRentalId(houseRental.getId()); |
| | | if (null==houseTenantVO.getId()){ |
| | | // 新增 |
| | | HouseTenantEntity houseTenant= new HouseTenantEntity(); |
| | | List<String> phoneList = new ArrayList<>(); |
| | | |
| | | 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); |
| | | for (HouseholdEntity householdEntity : list) { |
| | | if (null == householdEntity.getId()) { |
| | | // 新增 |
| | | householdEntity.setHouseCode(houseRental.getHouseCode()); |
| | | householdEntity.setHousingRentalId(houseRental.getId()); |
| | | householdEntity.setRelationship(18); |
| | | householdEntity.setResidentialStatus(1); |
| | | householdEntity.setRoleType(2); |
| | | addList.add(householdEntity); |
| | | phoneList.add(householdEntity.getPhoneNumber()); |
| | | } else { |
| | | newList.add(householdEntity); |
| | | } |
| | | } |
| | | // 遍历去差集,判断是新增还是删除还是更新 |
| | |
| | | |
| | | // 批量新增 |
| | | if (addList.size()>0) { |
| | | addFlag = houseTenantService.saveBatch(addList); |
| | | addFlag = iHouseholdService.saveBatch(addList); |
| | | } |
| | | // 批量修改 |
| | | if (updateList.size()>0) { |
| | | updateFlag = houseTenantService.updateBatchById(updateList); |
| | | if (updateList.size() > 0) { |
| | | updateFlag = iHouseholdService.updateBatchById(updateList); |
| | | for (HouseholdEntity householdEntity : updateList) { |
| | | phoneList.add(householdEntity.getPhoneNumber()); |
| | | } |
| | | } |
| | | // 批量删除 |
| | | if (removeList.size()>0) { |
| | | removeFlag = houseTenantService.removeBatchByIds(removeList); |
| | | if (removeList.size() > 0) { |
| | | removeFlag = iHouseholdService.removeBatchByIds(removeList); |
| | | } |
| | | try { |
| | | // 查询租户是否网格员身份的,给网格员设置居民角色 |
| | | IUserService bean = SpringUtils.getBean(IUserService.class); |
| | | String str = "1717429261910528001"; |
| | | List<User> list2 = bean.list(Wrappers.<User>lambdaQuery() |
| | | .in(User::getPhone, phoneList) |
| | | .like(User::getRoleId, str)); |
| | | for (User user : list2) { |
| | | boolean contains = user.getRoleId().contains("1717429059648606209"); |
| | | if (contains) { |
| | | continue; |
| | | } |
| | | user.setRoleId(user.getRoleId() + ",1717429059648606209"); |
| | | } |
| | | bean.updateBatchById(list2); |
| | | } catch (Exception e) { |
| | | log.error("保存用户角色为居民:", e); |
| | | } |
| | | // 返回 |
| | | return update && addFlag && updateFlag && removeFlag; |