fix(authorization): 自助申请授权状态设为AUTHORIZED而非PENDING
问题:自助申请的社区/市团队/省团队授权创建时状态为PENDING, 导致在推荐关系查询中无法找到这些授权(查询只匹配AUTHORIZED状态) 解决方案: - 新增 createSelfAppliedCommunity 工厂方法,状态直接设为 AUTHORIZED - 新增 createSelfAppliedAuthCityCompany 工厂方法 - 新增 createSelfAppliedAuthProvinceCompany 工厂方法 - 更新事件类型允许 authorizedBy 为 null(表示自助申请) - 自助申请处理方法改用新的工厂方法 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
857beeb196
commit
0506a3547c
|
|
@ -2865,9 +2865,9 @@ export class AuthorizationApplicationService {
|
||||||
throw new ApplicationError('您已拥有社区授权')
|
throw new ApplicationError('您已拥有社区授权')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 直接创建授权(自助申请的社区授权直接生效)
|
// 直接创建授权(自助申请的社区授权直接生效,状态为 AUTHORIZED)
|
||||||
const userId = UserId.create(command.userId, command.accountSequence)
|
const userId = UserId.create(command.userId, command.accountSequence)
|
||||||
const authorization = AuthorizationRole.createCommunityAuth({
|
const authorization = AuthorizationRole.createSelfAppliedCommunity({
|
||||||
userId,
|
userId,
|
||||||
communityName: command.communityName!,
|
communityName: command.communityName!,
|
||||||
})
|
})
|
||||||
|
|
@ -2906,9 +2906,9 @@ export class AuthorizationApplicationService {
|
||||||
throw new ApplicationError('该市已有授权市公司')
|
throw new ApplicationError('该市已有授权市公司')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建授权市公司授权
|
// 创建授权市公司授权(自助申请直接生效,状态为 AUTHORIZED)
|
||||||
const userId = UserId.create(command.userId, command.accountSequence)
|
const userId = UserId.create(command.userId, command.accountSequence)
|
||||||
const authorization = AuthorizationRole.createAuthCityCompany({
|
const authorization = AuthorizationRole.createSelfAppliedAuthCityCompany({
|
||||||
userId,
|
userId,
|
||||||
cityCode: command.cityCode!,
|
cityCode: command.cityCode!,
|
||||||
cityName: command.cityName!,
|
cityName: command.cityName!,
|
||||||
|
|
@ -2948,9 +2948,9 @@ export class AuthorizationApplicationService {
|
||||||
throw new ApplicationError('该省已有授权省公司')
|
throw new ApplicationError('该省已有授权省公司')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建授权省公司授权
|
// 创建授权省公司授权(自助申请直接生效,状态为 AUTHORIZED)
|
||||||
const userId = UserId.create(command.userId, command.accountSequence)
|
const userId = UserId.create(command.userId, command.accountSequence)
|
||||||
const authorization = AuthorizationRole.createAuthProvinceCompany({
|
const authorization = AuthorizationRole.createSelfAppliedAuthProvinceCompany({
|
||||||
userId,
|
userId,
|
||||||
provinceCode: command.provinceCode!,
|
provinceCode: command.provinceCode!,
|
||||||
provinceName: command.provinceName!,
|
provinceName: command.provinceName!,
|
||||||
|
|
|
||||||
|
|
@ -283,6 +283,50 @@ export class AuthorizationRole extends AggregateRoot {
|
||||||
return auth
|
return auth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 工厂方法 - 自助申请社区授权(直接生效,无需审核)
|
||||||
|
static createSelfAppliedCommunity(params: { userId: UserId; communityName: string }): AuthorizationRole {
|
||||||
|
const now = new Date()
|
||||||
|
const auth = new AuthorizationRole({
|
||||||
|
authorizationId: AuthorizationId.generate(),
|
||||||
|
userId: params.userId,
|
||||||
|
roleType: RoleType.COMMUNITY,
|
||||||
|
regionCode: RegionCode.create(params.communityName),
|
||||||
|
regionName: params.communityName,
|
||||||
|
status: AuthorizationStatus.AUTHORIZED, // 自助申请直接生效
|
||||||
|
displayTitle: params.communityName,
|
||||||
|
authorizedAt: now,
|
||||||
|
authorizedBy: null, // 自助申请无管理员
|
||||||
|
revokedAt: null,
|
||||||
|
revokedBy: null,
|
||||||
|
revokeReason: null,
|
||||||
|
assessmentConfig: AssessmentConfig.forCommunity(),
|
||||||
|
requireLocalPercentage: 0,
|
||||||
|
exemptFromPercentageCheck: true,
|
||||||
|
benefitActive: false, // 权益需要达到考核目标后激活
|
||||||
|
benefitActivatedAt: null,
|
||||||
|
benefitDeactivatedAt: null,
|
||||||
|
benefitValidUntil: null,
|
||||||
|
lastAssessmentMonth: null,
|
||||||
|
monthlyTreesAdded: 0,
|
||||||
|
lastMonthTreesAdded: 0,
|
||||||
|
currentMonthIndex: 0,
|
||||||
|
deletedAt: null,
|
||||||
|
createdAt: now,
|
||||||
|
updatedAt: now,
|
||||||
|
})
|
||||||
|
|
||||||
|
auth.addDomainEvent(
|
||||||
|
new CommunityAuthorizedEvent({
|
||||||
|
authorizationId: auth.authorizationId.value,
|
||||||
|
userId: params.userId.value,
|
||||||
|
communityName: params.communityName,
|
||||||
|
authorizedBy: null, // 自助申请
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
return auth
|
||||||
|
}
|
||||||
|
|
||||||
// 工厂方法 - 管理员直接授权社区
|
// 工厂方法 - 管理员直接授权社区
|
||||||
static createCommunity(params: {
|
static createCommunity(params: {
|
||||||
userId: UserId
|
userId: UserId
|
||||||
|
|
@ -381,6 +425,55 @@ export class AuthorizationRole extends AggregateRoot {
|
||||||
return auth
|
return auth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 工厂方法 - 自助申请授权省公司(直接生效,无需审核)
|
||||||
|
static createSelfAppliedAuthProvinceCompany(params: {
|
||||||
|
userId: UserId
|
||||||
|
provinceCode: string
|
||||||
|
provinceName: string
|
||||||
|
}): AuthorizationRole {
|
||||||
|
const now = new Date()
|
||||||
|
const auth = new AuthorizationRole({
|
||||||
|
authorizationId: AuthorizationId.generate(),
|
||||||
|
userId: params.userId,
|
||||||
|
roleType: RoleType.AUTH_PROVINCE_COMPANY,
|
||||||
|
regionCode: RegionCode.create(params.provinceCode),
|
||||||
|
regionName: params.provinceName,
|
||||||
|
status: AuthorizationStatus.AUTHORIZED, // 自助申请直接生效
|
||||||
|
displayTitle: `授权${params.provinceName}`,
|
||||||
|
authorizedAt: now,
|
||||||
|
authorizedBy: null, // 自助申请无管理员
|
||||||
|
revokedAt: null,
|
||||||
|
revokedBy: null,
|
||||||
|
revokeReason: null,
|
||||||
|
assessmentConfig: AssessmentConfig.forAuthProvince(),
|
||||||
|
requireLocalPercentage: 5.0,
|
||||||
|
exemptFromPercentageCheck: false,
|
||||||
|
benefitActive: false, // 权益需要达到考核目标后激活
|
||||||
|
benefitActivatedAt: null,
|
||||||
|
benefitDeactivatedAt: null,
|
||||||
|
benefitValidUntil: null,
|
||||||
|
lastAssessmentMonth: null,
|
||||||
|
monthlyTreesAdded: 0,
|
||||||
|
lastMonthTreesAdded: 0,
|
||||||
|
currentMonthIndex: 0,
|
||||||
|
deletedAt: null,
|
||||||
|
createdAt: now,
|
||||||
|
updatedAt: now,
|
||||||
|
})
|
||||||
|
|
||||||
|
auth.addDomainEvent(
|
||||||
|
new AuthProvinceCompanyGrantedEvent({
|
||||||
|
authorizationId: auth.authorizationId.value,
|
||||||
|
userId: params.userId.value,
|
||||||
|
provinceCode: params.provinceCode,
|
||||||
|
provinceName: params.provinceName,
|
||||||
|
authorizedBy: null, // 自助申请
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
return auth
|
||||||
|
}
|
||||||
|
|
||||||
// 工厂方法 - 创建正式省公司
|
// 工厂方法 - 创建正式省公司
|
||||||
// 授权即激活,开始按月考核(150, 300, 600, 1200, 2400, 4800, 9600, 19200, 11750)
|
// 授权即激活,开始按月考核(150, 300, 600, 1200, 2400, 4800, 9600, 19200, 11750)
|
||||||
static createProvinceCompany(params: {
|
static createProvinceCompany(params: {
|
||||||
|
|
@ -481,6 +574,55 @@ export class AuthorizationRole extends AggregateRoot {
|
||||||
return auth
|
return auth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 工厂方法 - 自助申请授权市公司(直接生效,无需审核)
|
||||||
|
static createSelfAppliedAuthCityCompany(params: {
|
||||||
|
userId: UserId
|
||||||
|
cityCode: string
|
||||||
|
cityName: string
|
||||||
|
}): AuthorizationRole {
|
||||||
|
const now = new Date()
|
||||||
|
const auth = new AuthorizationRole({
|
||||||
|
authorizationId: AuthorizationId.generate(),
|
||||||
|
userId: params.userId,
|
||||||
|
roleType: RoleType.AUTH_CITY_COMPANY,
|
||||||
|
regionCode: RegionCode.create(params.cityCode),
|
||||||
|
regionName: params.cityName,
|
||||||
|
status: AuthorizationStatus.AUTHORIZED, // 自助申请直接生效
|
||||||
|
displayTitle: `授权${params.cityName}`,
|
||||||
|
authorizedAt: now,
|
||||||
|
authorizedBy: null, // 自助申请无管理员
|
||||||
|
revokedAt: null,
|
||||||
|
revokedBy: null,
|
||||||
|
revokeReason: null,
|
||||||
|
assessmentConfig: AssessmentConfig.forAuthCity(),
|
||||||
|
requireLocalPercentage: 5.0,
|
||||||
|
exemptFromPercentageCheck: false,
|
||||||
|
benefitActive: false, // 权益需要达到考核目标后激活
|
||||||
|
benefitActivatedAt: null,
|
||||||
|
benefitDeactivatedAt: null,
|
||||||
|
benefitValidUntil: null,
|
||||||
|
lastAssessmentMonth: null,
|
||||||
|
monthlyTreesAdded: 0,
|
||||||
|
lastMonthTreesAdded: 0,
|
||||||
|
currentMonthIndex: 0,
|
||||||
|
deletedAt: null,
|
||||||
|
createdAt: now,
|
||||||
|
updatedAt: now,
|
||||||
|
})
|
||||||
|
|
||||||
|
auth.addDomainEvent(
|
||||||
|
new AuthCityCompanyGrantedEvent({
|
||||||
|
authorizationId: auth.authorizationId.value,
|
||||||
|
userId: params.userId.value,
|
||||||
|
cityCode: params.cityCode,
|
||||||
|
cityName: params.cityName,
|
||||||
|
authorizedBy: null, // 自助申请
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
return auth
|
||||||
|
}
|
||||||
|
|
||||||
// 工厂方法 - 创建正式市公司
|
// 工厂方法 - 创建正式市公司
|
||||||
// 授权即激活,开始按月考核(30, 60, 120, 240, 480, 960, 1920, 3840, 2350)
|
// 授权即激活,开始按月考核(30, 60, 120, 240, 480, 960, 1920, 3840, 2350)
|
||||||
static createCityCompany(params: {
|
static createCityCompany(params: {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { DomainEvent } from './domain-event.base'
|
import { DomainEvent } from './domain-event.base'
|
||||||
import { RoleType } from '@/domain/enums'
|
import { RoleType } from '@/domain/enums'
|
||||||
|
|
||||||
// 社区授权事件(管理员直接授权)
|
// 社区授权事件(管理员直接授权或自助申请)
|
||||||
export class CommunityAuthorizedEvent extends DomainEvent {
|
export class CommunityAuthorizedEvent extends DomainEvent {
|
||||||
readonly eventType = 'authorization.community.authorized'
|
readonly eventType = 'authorization.community.authorized'
|
||||||
readonly aggregateId: string
|
readonly aggregateId: string
|
||||||
|
|
@ -9,14 +9,14 @@ export class CommunityAuthorizedEvent extends DomainEvent {
|
||||||
authorizationId: string
|
authorizationId: string
|
||||||
userId: string
|
userId: string
|
||||||
communityName: string
|
communityName: string
|
||||||
authorizedBy: string
|
authorizedBy: string | null // null 表示自助申请
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(data: {
|
constructor(data: {
|
||||||
authorizationId: string
|
authorizationId: string
|
||||||
userId: string
|
userId: string
|
||||||
communityName: string
|
communityName: string
|
||||||
authorizedBy: string
|
authorizedBy: string | null
|
||||||
}) {
|
}) {
|
||||||
super()
|
super()
|
||||||
this.aggregateId = data.authorizationId
|
this.aggregateId = data.authorizationId
|
||||||
|
|
@ -146,7 +146,7 @@ export class AuthProvinceCompanyGrantedEvent extends DomainEvent {
|
||||||
userId: string
|
userId: string
|
||||||
provinceCode: string
|
provinceCode: string
|
||||||
provinceName: string
|
provinceName: string
|
||||||
authorizedBy: string
|
authorizedBy: string | null // null 表示自助申请
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(data: {
|
constructor(data: {
|
||||||
|
|
@ -154,7 +154,7 @@ export class AuthProvinceCompanyGrantedEvent extends DomainEvent {
|
||||||
userId: string
|
userId: string
|
||||||
provinceCode: string
|
provinceCode: string
|
||||||
provinceName: string
|
provinceName: string
|
||||||
authorizedBy: string
|
authorizedBy: string | null
|
||||||
}) {
|
}) {
|
||||||
super()
|
super()
|
||||||
this.aggregateId = data.authorizationId
|
this.aggregateId = data.authorizationId
|
||||||
|
|
@ -171,7 +171,7 @@ export class AuthCityCompanyGrantedEvent extends DomainEvent {
|
||||||
userId: string
|
userId: string
|
||||||
cityCode: string
|
cityCode: string
|
||||||
cityName: string
|
cityName: string
|
||||||
authorizedBy: string
|
authorizedBy: string | null // null 表示自助申请
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(data: {
|
constructor(data: {
|
||||||
|
|
@ -179,7 +179,7 @@ export class AuthCityCompanyGrantedEvent extends DomainEvent {
|
||||||
userId: string
|
userId: string
|
||||||
cityCode: string
|
cityCode: string
|
||||||
cityName: string
|
cityName: string
|
||||||
authorizedBy: string
|
authorizedBy: string | null
|
||||||
}) {
|
}) {
|
||||||
super()
|
super()
|
||||||
this.aggregateId = data.authorizationId
|
this.aggregateId = data.authorizationId
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue