修改团队政策
This commit is contained in:
parent
d48866cc1c
commit
29ee759b39
@ -1,6 +1,8 @@
|
|||||||
spring:
|
spring:
|
||||||
cloud:
|
cloud:
|
||||||
gateway:
|
gateway:
|
||||||
|
default-filters:
|
||||||
|
- DedupeResponseHeader=Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_LAST
|
||||||
globalcors:
|
globalcors:
|
||||||
add-to-simple-url-handler-mapping: true,
|
add-to-simple-url-handler-mapping: true,
|
||||||
cors-configurations:
|
cors-configurations:
|
||||||
|
|||||||
@ -2,21 +2,26 @@ package com.red.circle.other.app.command.team.query;
|
|||||||
|
|
||||||
import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd;
|
import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd;
|
||||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||||
|
import com.red.circle.other.infra.common.sys.CountryCodeAliasSupport;
|
||||||
import com.red.circle.other.app.convertor.team.TeamAppConvertor;
|
import com.red.circle.other.app.convertor.team.TeamAppConvertor;
|
||||||
import com.red.circle.other.app.dto.clientobject.team.TeamPolicyManagerCO;
|
import com.red.circle.other.app.dto.clientobject.team.TeamPolicyManagerCO;
|
||||||
import com.red.circle.other.app.service.user.user.UserProfileService;
|
|
||||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||||
import com.red.circle.other.domain.model.user.UserProfile;
|
import com.red.circle.other.domain.model.user.UserProfile;
|
||||||
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamPolicyManager;
|
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamPolicyManager;
|
||||||
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamProfile;
|
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamProfile;
|
||||||
|
import com.red.circle.other.infra.database.mongo.entity.user.region.SysRegionConfig;
|
||||||
import com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils;
|
import com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils;
|
||||||
import com.red.circle.other.infra.database.mongo.service.team.team.TeamPolicyManagerService;
|
import com.red.circle.other.infra.database.mongo.service.team.team.TeamPolicyManagerService;
|
||||||
import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService;
|
import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService;
|
||||||
|
import com.red.circle.other.infra.database.mongo.service.user.region.SysRegionConfigService;
|
||||||
import com.red.circle.other.inner.asserts.team.TeamErrorCode;
|
import com.red.circle.other.inner.asserts.team.TeamErrorCode;
|
||||||
|
import com.red.circle.tool.core.text.StringUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,17 +37,45 @@ public class TeamReleasePolicyQryExe {
|
|||||||
private final TeamProfileService teamProfileService;
|
private final TeamProfileService teamProfileService;
|
||||||
private final TeamPolicyManagerService teamPolicyManagerService;
|
private final TeamPolicyManagerService teamPolicyManagerService;
|
||||||
private final UserProfileGateway userProfileGateway;
|
private final UserProfileGateway userProfileGateway;
|
||||||
|
private final SysRegionConfigService sysRegionConfigService;
|
||||||
|
private final CountryCodeAliasSupport countryCodeAliasSupport;
|
||||||
|
|
||||||
public TeamPolicyManagerCO execute(AppIdLongCmd cmd) {
|
public TeamPolicyManagerCO execute(AppIdLongCmd cmd) {
|
||||||
TeamProfile teamProfile = teamProfileService.getById(cmd.getId());
|
TeamProfile teamProfile = teamProfileService.getById(cmd.getId());
|
||||||
ResponseAssert.notNull(TeamErrorCode.TEAM_NOT_FOUND, teamProfile);
|
ResponseAssert.notNull(TeamErrorCode.TEAM_NOT_FOUND, teamProfile);
|
||||||
|
|
||||||
UserProfile userProfile = userProfileGateway.getByUserId(teamProfile.getOwnUserId());
|
UserProfile userProfile = userProfileGateway.getByUserId(teamProfile.getOwnUserId());
|
||||||
|
String countryCode = Objects.nonNull(userProfile) ? userProfile.getCountryCode() : null;
|
||||||
|
String policyRegion = resolveOwnerCountryRegion(teamProfile, countryCode);
|
||||||
|
|
||||||
Map<String, TeamPolicyManager> policyManagerMap = teamPolicyManagerService.mapRegionReleaseWithCountry(Set.of(teamProfile.getRegion()));
|
Map<String, TeamPolicyManager> policyManagerMap = teamPolicyManagerService.mapRegionReleaseWithCountry(Set.of(policyRegion));
|
||||||
TeamPolicyManager teamPolicyManager = TeamBillCycleUtils.getPolicyFromMap(policyManagerMap, teamProfile.getRegion(), userProfile.getCountryCode());
|
TeamPolicyManager teamPolicyManager = TeamBillCycleUtils.getPolicyFromMap(policyManagerMap, policyRegion, countryCode);
|
||||||
|
|
||||||
return teamAppConvertor.toTeamPolicyManagerCO(teamPolicyManager);
|
return teamAppConvertor.toTeamPolicyManagerCO(teamPolicyManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String resolveOwnerCountryRegion(TeamProfile teamProfile, String countryCode) {
|
||||||
|
List<SysRegionConfig> regionConfigs = sysRegionConfigService.listAvailable(teamProfile.getSysOrigin());
|
||||||
|
if (regionConfigs == null || regionConfigs.isEmpty()) {
|
||||||
|
return teamProfile.getRegion();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(countryCode)) {
|
||||||
|
SysRegionConfig countryRegion = regionConfigs.stream()
|
||||||
|
.filter(region -> StringUtils.isNotBlank(region.getCountryCodes()))
|
||||||
|
.filter(region -> countryCodeAliasSupport.containsCode(region.getCountryCodes(), countryCode))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
if (Objects.nonNull(countryRegion)) {
|
||||||
|
return countryRegion.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return regionConfigs.stream()
|
||||||
|
.filter(region -> StringUtils.equalsIgnoreCase("OTHER", region.getRegionCode()))
|
||||||
|
.findFirst()
|
||||||
|
.map(SysRegionConfig::getId)
|
||||||
|
.orElse(teamProfile.getRegion());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,89 @@
|
|||||||
|
package com.red.circle.other.app.command.team.query;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd;
|
||||||
|
import com.red.circle.other.app.convertor.team.TeamAppConvertor;
|
||||||
|
import com.red.circle.other.app.dto.clientobject.team.TeamPolicyManagerCO;
|
||||||
|
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||||
|
import com.red.circle.other.domain.model.user.UserProfile;
|
||||||
|
import com.red.circle.other.infra.common.sys.CountryCodeAliasSupport;
|
||||||
|
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamPolicyManager;
|
||||||
|
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamProfile;
|
||||||
|
import com.red.circle.other.infra.database.mongo.entity.user.region.SysRegionConfig;
|
||||||
|
import com.red.circle.other.infra.database.mongo.service.team.team.TeamPolicyManagerService;
|
||||||
|
import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService;
|
||||||
|
import com.red.circle.other.infra.database.mongo.service.user.region.SysRegionConfigService;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class TeamReleasePolicyQryExeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void executeShouldResolvePolicyByTeamOwnerCountryRegion() {
|
||||||
|
TeamAppConvertor teamAppConvertor = mock(TeamAppConvertor.class);
|
||||||
|
TeamProfileService teamProfileService = mock(TeamProfileService.class);
|
||||||
|
TeamPolicyManagerService teamPolicyManagerService = mock(TeamPolicyManagerService.class);
|
||||||
|
UserProfileGateway userProfileGateway = mock(UserProfileGateway.class);
|
||||||
|
SysRegionConfigService sysRegionConfigService = mock(SysRegionConfigService.class);
|
||||||
|
CountryCodeAliasSupport countryCodeAliasSupport = mock(CountryCodeAliasSupport.class);
|
||||||
|
TeamReleasePolicyQryExe exe = new TeamReleasePolicyQryExe(
|
||||||
|
teamAppConvertor,
|
||||||
|
teamProfileService,
|
||||||
|
teamPolicyManagerService,
|
||||||
|
userProfileGateway,
|
||||||
|
sysRegionConfigService,
|
||||||
|
countryCodeAliasSupport
|
||||||
|
);
|
||||||
|
|
||||||
|
AppIdLongCmd cmd = new AppIdLongCmd();
|
||||||
|
cmd.setId(2047235247724072961L);
|
||||||
|
|
||||||
|
TeamProfile teamProfile = new TeamProfile()
|
||||||
|
.setId(2047235247724072961L)
|
||||||
|
.setOwnUserId(2047206645188063233L)
|
||||||
|
.setSysOrigin("LIKEI")
|
||||||
|
.setRegion("jp-region");
|
||||||
|
UserProfile ownerProfile = new UserProfile();
|
||||||
|
ownerProfile.setId(2047206645188063233L);
|
||||||
|
ownerProfile.setCountryCode("PK");
|
||||||
|
SysRegionConfig jpRegion = new SysRegionConfig()
|
||||||
|
.setId("jp-region")
|
||||||
|
.setSysOrigin("LIKEI")
|
||||||
|
.setRegionCode("JP")
|
||||||
|
.setCountryCodes("JP");
|
||||||
|
SysRegionConfig pkRegion = new SysRegionConfig()
|
||||||
|
.setId("pk-region")
|
||||||
|
.setSysOrigin("LIKEI")
|
||||||
|
.setRegionCode("PK")
|
||||||
|
.setCountryCodes("PK");
|
||||||
|
TeamPolicyManager policyManager = new TeamPolicyManager()
|
||||||
|
.setId(1L)
|
||||||
|
.setRegion("pk-region")
|
||||||
|
.setCountryCode("PK");
|
||||||
|
TeamPolicyManagerCO policyManagerCO = new TeamPolicyManagerCO()
|
||||||
|
.setId(1L)
|
||||||
|
.setRegion("pk-region");
|
||||||
|
|
||||||
|
when(teamProfileService.getById(2047235247724072961L)).thenReturn(teamProfile);
|
||||||
|
when(userProfileGateway.getByUserId(2047206645188063233L)).thenReturn(ownerProfile);
|
||||||
|
when(sysRegionConfigService.listAvailable("LIKEI")).thenReturn(List.of(jpRegion, pkRegion));
|
||||||
|
when(countryCodeAliasSupport.containsCode("JP", "PK")).thenReturn(false);
|
||||||
|
when(countryCodeAliasSupport.containsCode("PK", "PK")).thenReturn(true);
|
||||||
|
when(teamPolicyManagerService.mapRegionReleaseWithCountry(Set.of("pk-region"))).thenReturn(
|
||||||
|
Map.of("pk-region_PK", policyManager)
|
||||||
|
);
|
||||||
|
when(teamAppConvertor.toTeamPolicyManagerCO(policyManager)).thenReturn(policyManagerCO);
|
||||||
|
|
||||||
|
TeamPolicyManagerCO result = exe.execute(cmd);
|
||||||
|
|
||||||
|
assertSame(policyManagerCO, result);
|
||||||
|
verify(teamPolicyManagerService).mapRegionReleaseWithCountry(Set.of("pk-region"));
|
||||||
|
verify(teamAppConvertor).toTeamPolicyManagerCO(policyManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -52,11 +52,11 @@ class UpdateUserProfileCmdExeTest {
|
|||||||
cmd.setReqSysOrigin(ReqSysOrigin.of("LIKEI", "LIKEI"));
|
cmd.setReqSysOrigin(ReqSysOrigin.of("LIKEI", "LIKEI"));
|
||||||
cmd.setCountryId(2L);
|
cmd.setCountryId(2L);
|
||||||
|
|
||||||
UserProfile currentUserProfile = new UserProfile()
|
UserProfile currentUserProfile = new UserProfile();
|
||||||
.setId(1L)
|
currentUserProfile.setId(1L);
|
||||||
.setCountryId(1L)
|
currentUserProfile.setCountryId(1L);
|
||||||
.setCountryCode("KSA")
|
currentUserProfile.setCountryCode("KSA");
|
||||||
.setCountryName("KSA");
|
currentUserProfile.setCountryName("KSA");
|
||||||
UserProfile updateUserProfile = new UserProfile();
|
UserProfile updateUserProfile = new UserProfile();
|
||||||
SysCountryCode newCountry = new SysCountryCode()
|
SysCountryCode newCountry = new SysCountryCode()
|
||||||
.setId(2L)
|
.setId(2L)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user