发起审核的时候新增关联关系

master
zzy 2026-04-23 17:22:11 +08:00
parent 728aa92f0c
commit 40307148ac
4 changed files with 38 additions and 7 deletions

View File

@ -4,11 +4,13 @@ import com.fjrcloud.community.framework.common.pojo.CommonResult;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunitySimpleRespVO;
import com.fjrcloud.community.module.community.service.community.CommunityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@ -28,8 +30,10 @@ public class AppCommunityController {
@GetMapping("/simple-list")
@Operation(summary = "获取小区精简列表")
public CommonResult<List<CommunitySimpleRespVO>> getCommunitySimpleList() {
List<CommunitySimpleRespVO> list = communityService.getAppCommunitySimpleList();
@Parameter(name = "all", description = "是否获取全部小区忽略租户隔离默认false", example = "false")
public CommonResult<List<CommunitySimpleRespVO>> getCommunitySimpleList(
@RequestParam(value = "all", required = false, defaultValue = "false") Boolean all) {
List<CommunitySimpleRespVO> list = communityService.getAppCommunitySimpleList(all);
return success(list);
}

View File

@ -82,8 +82,9 @@ public interface CommunityService {
/**
* App
*
* @param all
* @return
*/
List<CommunitySimpleRespVO> getAppCommunitySimpleList();
List<CommunitySimpleRespVO> getAppCommunitySimpleList(Boolean all);
}

View File

@ -379,9 +379,17 @@ public class CommunityServiceImpl implements CommunityService {
}
@Override
public List<CommunitySimpleRespVO> getAppCommunitySimpleList() {
// App端查询当前租户下的小区列表
List<CommunityDO> communities = communityMapper.selectList();
public List<CommunitySimpleRespVO> getAppCommunitySimpleList(Boolean all) {
List<CommunityDO> communities;
if (Boolean.TRUE.equals(all)) {
// 获取全部小区,忽略租户隔离
communities = TenantUtils.executeIgnore(() -> communityMapper.selectList());
} else {
// 只获取当前租户下的小区
communities = communityMapper.selectList();
}
return communities.stream()
.map(community -> CommunitySimpleRespVO.builder()
.id(community.getId())

View File

@ -18,6 +18,7 @@ import com.fjrcloud.community.module.community.dal.mysql.memberhouse.MemberHouse
import com.fjrcloud.community.module.community.service.community.CommunityService;
import com.fjrcloud.community.module.member.dal.dataobject.user.MemberUserDO;
import com.fjrcloud.community.module.member.service.user.MemberUserService;
import com.fjrcloud.community.module.member.service.user.MemberUserTenantRelService;
import com.fjrcloud.community.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
import com.fjrcloud.community.module.system.service.oauth2.OAuth2TokenService;
import lombok.extern.slf4j.Slf4j;
@ -60,6 +61,9 @@ public class MemberHouseServiceImpl implements MemberHouseService {
@Resource
private OAuth2TokenService oauth2TokenService;
@Resource
private MemberUserTenantRelService memberUserTenantRelService;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createMemberHouse(MemberHouseSaveReqVO createReqVO) {
@ -96,6 +100,13 @@ public class MemberHouseServiceImpl implements MemberHouseService {
memberHouse.setTenantId(createReqVO.getCommunityId());
memberHouseMapper.insert(memberHouse);
// 5. 将用户关联到该小区(租户),如果是第一个小区则设为默认
List<MemberHouseDO> userHouses = memberHouseMapper.selectListByMemberId(memberHouse.getMemberId());
boolean isFirstHouse = userHouses.size() == 1;
memberUserTenantRelService.assignUserToTenant(memberHouse.getMemberId(), createReqVO.getCommunityId(), isFirstHouse);
log.info("[createMemberHouseForApp][用户({}) 发起房屋审核,自动关联租户({}),是否默认({})]",
memberHouse.getMemberId(), createReqVO.getCommunityId(), isFirstHouse);
return memberHouse.getId();
}
@ -308,6 +319,13 @@ public class MemberHouseServiceImpl implements MemberHouseService {
memberHouse.setTenantId(createReqVO.getCommunityId());
memberHouseMapper.insert(memberHouse);
// 4. 将用户关联到该小区(租户),如果是第一个小区则设为默认
List<MemberHouseDO> userHouses = memberHouseMapper.selectListByMemberId(memberId);
boolean isFirstHouse = userHouses.size() == 1;
memberUserTenantRelService.assignUserToTenant(memberId, createReqVO.getCommunityId(), isFirstHouse);
log.info("[createMemberHouseForApp][用户({}) 发起房屋审核,自动关联租户({}),是否默认({})]",
memberId, createReqVO.getCommunityId(), isFirstHouse);
return memberHouse.getId();
}
@ -405,7 +423,7 @@ public class MemberHouseServiceImpl implements MemberHouseService {
// 8. 如果小区变了需要重新登录生成新token
if (communityChanged) {
log.info("会员[{}]切换小区:从[{}]切换到[{}],房屋地址:{}",
log.info("会员[{}]切换小区:从[{}]切换到[{}],房屋地址:{}",
memberId, currentTenantId, communityId, houseAddress);
// 在新小区租户上下文中生成新的token