| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import liquibase.repackaged.org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.common.param.CommonParamSet; |
| | | import org.springblade.common.utils.SpringUtils; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.DigestUtil; |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | import org.springblade.modules.house.entity.HouseRentalEntity; |
| | | import org.springblade.modules.house.entity.HouseholdEntity; |
| | |
| | | import org.springblade.modules.house.vo.HouseRentalVO; |
| | | import org.springblade.modules.house.vo.HouseholdVO; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.entity.UserInfo; |
| | | import org.springblade.modules.system.service.IUserService; |
| | | import org.springblade.modules.system.vo.UserDetailVO; |
| | | import org.springblade.modules.system.vo.UserVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | |
| | | |
| | | /** |
| | | * 自定义分页查询 |
| | | * |
| | | * @param page |
| | | * @param houseRental |
| | | * @return |
| | | */ |
| | | @Override |
| | | 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){ |
| | | if (null != houseRental.getAuditStatus()) { |
| | | if (houseRental.getAuditStatus() == 0) { |
| | | houseRental.setAuditStatus(2); |
| | | } |
| | | } |
| | | List<HouseRentalTenantVO> houseRentalTenantVOS = baseMapper.selectHouseRentalPage(page, houseRental, list); |
| | | CommonParamSet<Object> commonParamSet = new CommonParamSet<>().invoke(HouseRentalTenantVO.class, houseRental); |
| | | List<HouseRentalTenantVO> houseRentalTenantVOS = baseMapper.selectHouseRentalPage(page, houseRental, |
| | | commonParamSet.getGridCodeList(), |
| | | commonParamSet.getRegionChildCodesList(), |
| | | commonParamSet.getIsAdministrator()); |
| | | for (HouseRentalTenantVO houseRentalTenantVO : houseRentalTenantVOS) { |
| | | if(houseRentalTenantVO.getStatus().equals(1)){ |
| | | houseRentalTenantVO.setAuditStatus(30); |
| | | if (houseRentalTenantVO.getStatus().equals(1)) { |
| | | houseRentalTenantVO.setStatus(30); |
| | | } |
| | | if(houseRentalTenantVO.getStatus().equals(0) && houseRentalTenantVO.getAuditStatus().equals(0)){ |
| | | houseRentalTenantVO.setAuditStatus(0); |
| | | if (houseRentalTenantVO.getStatus().equals(0) && houseRentalTenantVO.getAuditStatus().equals(0)) { |
| | | houseRentalTenantVO.setStatus(0); |
| | | } |
| | | if(houseRentalTenantVO.getStatus().equals(0) && houseRentalTenantVO.getAuditStatus().equals(1)){ |
| | | houseRentalTenantVO.setAuditStatus(1); |
| | | if (houseRentalTenantVO.getStatus().equals(0) && houseRentalTenantVO.getAuditStatus().equals(1)) { |
| | | houseRentalTenantVO.setStatus(1); |
| | | } |
| | | if(houseRentalTenantVO.getStatus().equals(0) && houseRentalTenantVO.getDldType().equals(3)){ |
| | | houseRentalTenantVO.setAuditStatus(20); |
| | | if (houseRentalTenantVO.getStatus().equals(0) && houseRentalTenantVO.getDldType().equals(3)) { |
| | | houseRentalTenantVO.setStatus(20); |
| | | } |
| | | if(houseRentalTenantVO.getStatus().equals(0) && houseRentalTenantVO.getDldType().equals(2)){ |
| | | houseRentalTenantVO.setAuditStatus(10); |
| | | if (houseRentalTenantVO.getStatus().equals(0) && houseRentalTenantVO.getDldType().equals(2)) { |
| | | houseRentalTenantVO.setStatus(10); |
| | | } |
| | | } |
| | | return page.setRecords(houseRentalTenantVOS); |
| | |
| | | |
| | | /** |
| | | * 查询房屋出租情况 |
| | | * |
| | | * @param code |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 自定义房屋出租新增 |
| | | * |
| | | * @param houseRentalVO |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean add(HouseRentalVO houseRentalVO) { |
| | | boolean flag = false; |
| | | houseRentalVO.setCreateUser(AuthUtil.getUserId()); |
| | | houseRentalVO.setCreateTime(new Date()); |
| | | houseRentalVO.setUpdateUser(AuthUtil.getUserId()); |
| | | houseRentalVO.setUpdateTime(new Date()); |
| | | //保存自身 |
| | | boolean save = save(houseRentalVO); |
| | | 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()); |
| | | }); |
| | | 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); |
| | | // 网格员新增默认是审核通过 |
| | | houseRentalVO.setAuditStatus(1); |
| | | // 获取请求头中的角色别名 |
| | | String roleName = SpringUtils.getRequestParam("roleName"); |
| | | // 居民 |
| | | if (!Strings.isBlank(roleName) && roleName.equals("inhabitant")) { |
| | | // 待审核 |
| | | houseRentalVO.setAuditStatus(0); |
| | | } |
| | | boolean saveBatch = iHouseholdService.saveBatch(householdEntityList); |
| | | //保存自身(租赁) |
| | | flag = save(houseRentalVO); |
| | | //保存到住户 |
| | | if (flag){ |
| | | flag = saveHousehold(houseRentalVO, flag); |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | return save && saveBatch; |
| | | /** |
| | | * 保存租户信息 |
| | | * |
| | | * @param houseRentalVO |
| | | * @param flag |
| | | * @return |
| | | */ |
| | | public boolean saveHousehold(HouseRentalVO houseRentalVO, boolean flag) { |
| | | if (houseRentalVO.getHouseholdVOList().size() > 0) { |
| | | houseRentalVO.getHouseholdVOList().forEach(e -> { |
| | | e.setHouseCode(houseRentalVO.getHouseCode()); |
| | | e.setHousingRentalId(houseRentalVO.getId()); |
| | | e.setRelationship(18); |
| | | e.setResidentialStatus(1); |
| | | if (!Strings.isBlank(e.getIdCard())){ |
| | | e.setCardType(111); |
| | | } |
| | | e.setRoleType(2); |
| | | // 添加住户 |
| | | iHouseholdService.save(e); |
| | | // 绑定用户 |
| | | bindUserHandle(e); |
| | | }); |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 租客和用户绑定 |
| | | * |
| | | * @param |
| | | */ |
| | | public User bindUserHandle(HouseholdEntity householdEntity) { |
| | | IUserService userService = SpringUtils.getBean(IUserService.class); |
| | | IHouseholdService householdService = SpringUtils.getBean(IHouseholdService.class); |
| | | User newUser = new User(); |
| | | if (null != householdEntity.getPhoneNumber() && !householdEntity.getPhoneNumber().equals("")) { |
| | | //根据手机号查询库里的数据 |
| | | List<User> list = userService.getUserListByPhoneOrAccount(householdEntity.getPhoneNumber()); |
| | | if (list.size()>0) { |
| | | User user = list.get(0); |
| | | //如果用户存在,则该用户id绑定场所 |
| | | householdEntity.setAssociatedUserId(user.getId()); |
| | | //更新住户信息 |
| | | householdService.updateById(householdEntity); |
| | | newUser = user; |
| | | // 判断用户是否包含了居民角色,不包含则需更新 |
| | | if (!user.getRoleId().contains("1717429059648606209")) { |
| | | user.setRoleId(user.getRoleId() + ",1717429059648606209"); |
| | | //更新 |
| | | userService.updateById(user); |
| | | } |
| | | } else { |
| | | //如果用户不存在,则新增一个用户 |
| | | newUser.setAccount(householdEntity.getPhoneNumber()); |
| | | newUser.setPhone(householdEntity.getPhoneNumber()); |
| | | newUser.setName(householdEntity.getName()); |
| | | newUser.setRealName(householdEntity.getName()); |
| | | // 社区群众部门 |
| | | newUser.setDeptId("1727979636479037441"); |
| | | // 目前暂定居民角色, |
| | | newUser.setRoleId("1717429059648606209"); |
| | | //默认密码为 123456 |
| | | newUser.setPassword("123456"); |
| | | // 设置机构 |
| | | // 用户新增 |
| | | boolean submit = userService.submit(newUser); |
| | | //绑定id |
| | | householdEntity.setAssociatedUserId(newUser.getId()); |
| | | //更新住户信息 |
| | | householdService.updateById(householdEntity); |
| | | } |
| | | } |
| | | return newUser; |
| | | } |
| | | |
| | | /** |
| | | * 出租屋 自定义删除 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | |
| | | boolean update = iHouseholdService.update(Wrappers.<HouseholdEntity>lambdaUpdate() |
| | | .set(HouseholdEntity::getIsDeleted, 1) |
| | | .eq(HouseholdEntity::getHousingRentalId, id)); |
| | | if (update) { |
| | | return true && b; |
| | | } |
| | | return false; |
| | | // 返回 |
| | | return b; |
| | | } |
| | | |
| | | /** |
| | | * 出租屋 自定义修改 |
| | | * |
| | | * @param houseRental |
| | | * @return |
| | | */ |
| | |
| | | boolean removeFlag = true; |
| | | houseRental.setUpdateUser(AuthUtil.getUserId()); |
| | | houseRental.setUpdateTime(new Date()); |
| | | // 获取请求头中的角色别名 |
| | | String roleName = SpringUtils.getRequestParam("roleName"); |
| | | // 居民 |
| | | if (!Strings.isBlank(roleName) && roleName.equals("inhabitant")) { |
| | | // 待审核 |
| | | houseRental.setAuditStatus(0); |
| | | } |
| | | //更新自身 |
| | | boolean update = updateById(houseRental); |
| | | // 查询对应已存在的租户 |
| | |
| | | List<HouseholdEntity> removeList = new ArrayList<>(); |
| | | // 找出需要新增的,否则组成新集合进行比对 |
| | | List<String> phoneList = new ArrayList<>(); |
| | | |
| | | IUserService userService = SpringUtils.getBean(IUserService.class); |
| | | for (HouseholdEntity householdEntity : list) { |
| | | if (null == householdEntity.getId()) { |
| | | // 新增 |
| | | User user = new User(); |
| | | // 新增或更新用户 |
| | | user = isSave(userService, householdEntity, user); |
| | | // 新增住户 |
| | | householdEntity.setHouseCode(houseRental.getHouseCode()); |
| | | householdEntity.setHousingRentalId(houseRental.getId()); |
| | | householdEntity.setRelationship(18); |
| | | householdEntity.setResidentialStatus(1); |
| | | householdEntity.setRoleType(2); |
| | | if (!Strings.isBlank(householdEntity.getIdCard())){ |
| | | householdEntity.setCardType(111); |
| | | } |
| | | if (user.getId() != null) { |
| | | householdEntity.setAssociatedUserId(user.getId()); |
| | | } |
| | | addList.add(householdEntity); |
| | | // 添加手机号 |
| | | phoneList.add(householdEntity.getPhoneNumber()); |
| | | } else { |
| | | newList.add(householdEntity); |
| | |
| | | // 取旧数据和新提交数据差集--删除 |
| | | 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) { |
| | | if (addList.size() > 0) { |
| | | addFlag = iHouseholdService.saveBatch(addList); |
| | | } |
| | | // 批量修改 |
| | | if (updateList.size() > 0) { |
| | | updateFlag = iHouseholdService.updateBatchById(updateList); |
| | | for (HouseholdEntity householdEntity : updateList) { |
| | | phoneList.add(householdEntity.getPhoneNumber()); |
| | | User user = new User(); |
| | | // 修改用户,用户存在则更新用户,不存在则新增用户 |
| | | user = isSave(userService, householdEntity, user); |
| | | if (user.getId() != null) { |
| | | householdEntity.setAssociatedUserId(user.getId()); |
| | | } |
| | | } |
| | | updateFlag = iHouseholdService.updateBatchById(updateList); |
| | | } |
| | | // 批量删除 |
| | | 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; |
| | | // 删除用户。判断用户是否有其他角色, |
| | | for (HouseholdEntity householdEntity : removeList) { |
| | | if (householdEntity.getAssociatedUserId() != null) { |
| | | User userVO = userService.getById(householdEntity.getAssociatedUserId()); |
| | | if (userVO.getRoleId().contains("1717429059648606209")) { |
| | | List<String> stringList = Arrays.asList(userVO.getRoleId().split(",")); |
| | | // 有其他角色 |
| | | if (stringList.size() >= 2) { |
| | | List<String> collect = stringList.stream().filter(item -> !item.equals("1717429059648606209")).collect(Collectors.toList()); |
| | | userVO.setRoleId(StringUtils.join(collect, ",")); |
| | | userService.updateById(userVO); |
| | | } else { |
| | | // 没有其他角色 |
| | | userVO.setRoleId(""); |
| | | boolean b = userService.updateById(userVO); |
| | | System.out.println(b); |
| | | } |
| | | } |
| | | } |
| | | user.setRoleId(user.getRoleId() + ",1717429059648606209"); |
| | | } |
| | | bean.updateBatchById(list2); |
| | | } catch (Exception e) { |
| | | log.error("保存用户角色为居民:", e); |
| | | } |
| | | // 返回 |
| | | return update && addFlag && updateFlag && removeFlag; |
| | | } |
| | | |
| | | /** |
| | | * 保存或更新用户 |
| | | * |
| | | * @param userService |
| | | * @param householdEntity |
| | | * @param user |
| | | * @return |
| | | */ |
| | | private User isSave(IUserService userService, HouseholdEntity householdEntity, User user) { |
| | | boolean save; |
| | | // 查询该住户是否有账号 |
| | | IUserService userService1 = SpringUtils.getBean(IUserService.class); |
| | | User user1 = userService1.getOne(Wrappers.<User>lambdaQuery() |
| | | .eq(User::getAccount, householdEntity.getPhoneNumber()) |
| | | .eq(User::getIsDeleted, 0).last("limit 1")); |
| | | if (user1 != null) { |
| | | user = user1; |
| | | user.setName(householdEntity.getName()); |
| | | user.setRealName(householdEntity.getName()); |
| | | if (StringUtils.isNoneBlank(user.getRoleId())) { |
| | | boolean contains = user.getRoleId().contains("1717429059648606209"); |
| | | if (!contains) { |
| | | user.setRoleId(user.getRoleId() + ",1717429059648606209"); |
| | | } |
| | | } else { |
| | | user.setRoleId("1717429059648606209"); |
| | | } |
| | | // 更新用户 |
| | | save = userService.updateById(user); |
| | | return user; |
| | | } |
| | | // 新增用户 |
| | | user.setAccount(householdEntity.getPhoneNumber()); |
| | | user.setUserType(1); |
| | | user.setPhone(householdEntity.getPhoneNumber()); |
| | | user.setRealName(householdEntity.getName()); |
| | | user.setName(householdEntity.getName()); |
| | | user.setPassword(DigestUtil.encrypt(CommonConstant.DEFAULT_PASSWORD)); |
| | | user.setRoleId("1717429059648606209"); |
| | | save = userService.save(user); |
| | | return user; |
| | | } |
| | | |
| | | /** |
| | | * 获取统计数据 |
| | | * |
| | | * @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()); |
| | | } |
| | | } |
| | | CommonParamSet<Object> commonParamSet = new CommonParamSet<>().invoke(HouseRentalTenantVO.class, houseRental); |
| | | // 查询 |
| | | List<HouseRentalStatistics> statistics = baseMapper.getStatistics(houseRental,list); |
| | | List<HouseRentalStatistics> statistics = baseMapper.getStatistics(houseRental, |
| | | commonParamSet.getGridCodeList(), |
| | | commonParamSet.getRegionChildCodesList(), |
| | | commonParamSet.getIsAdministrator()); |
| | | // 返回 |
| | | return statistics; |
| | | } |
| | | |
| | | /** |
| | | * 出租屋 确认 |
| | | * |
| | | * @param houseRental |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 导出租赁信息 |
| | | * |
| | | * @param houseRentalVO |
| | | * @return |
| | | */ |
| | |
| | | |
| | | @Override |
| | | public Integer getStatisticsCount(HouseRentalTenantVO houseRental) { |
| | | return baseMapper.getStatisticsCount(AuthUtil.getUserId()); |
| | | CommonParamSet<Object> commonParamSet = new CommonParamSet<>().invoke(HouseRentalTenantVO.class, houseRental); |
| | | return baseMapper.getStatisticsCount(houseRental, commonParamSet.getRegionChildCodesList(), |
| | | commonParamSet.getGridCodeList(), commonParamSet.getIsAdministrator()); |
| | | } |
| | | } |