add point
This commit is contained in:
@@ -26,6 +26,18 @@ export const permissionCodes = {
|
||||
update: "GAO:EVENT_RECORD:UPDATE",
|
||||
delete: "GAO:EVENT_RECORD:DELETE"
|
||||
},
|
||||
point: {
|
||||
accountRead: "GAO:POINT_ACCOUNT:READ",
|
||||
ledgerRead: "GAO:POINT_LEDGER:READ",
|
||||
adjust: "GAO:POINT:ADJUST",
|
||||
sourceValue: "GAO:POINT:SOURCE_VALUE"
|
||||
},
|
||||
pointRule: {
|
||||
create: "GAO:POINT_RULE:CREATE",
|
||||
read: "GAO:POINT_RULE:READ",
|
||||
update: "GAO:POINT_RULE:UPDATE",
|
||||
delete: "GAO:POINT_RULE:DELETE"
|
||||
},
|
||||
stat: {
|
||||
read: "GAO:STAT:READ"
|
||||
},
|
||||
@@ -95,6 +107,14 @@ export const gaoStoreScopePermissionCodes = [
|
||||
permissionCodes.eventRecord.export,
|
||||
permissionCodes.eventRecord.update,
|
||||
permissionCodes.eventRecord.delete,
|
||||
permissionCodes.point.accountRead,
|
||||
permissionCodes.point.ledgerRead,
|
||||
permissionCodes.point.adjust,
|
||||
permissionCodes.point.sourceValue,
|
||||
permissionCodes.pointRule.create,
|
||||
permissionCodes.pointRule.read,
|
||||
permissionCodes.pointRule.update,
|
||||
permissionCodes.pointRule.delete,
|
||||
permissionCodes.stat.read,
|
||||
permissionCodes.user.create,
|
||||
permissionCodes.user.read,
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import PointAPI from "@/api/PointAPI";
|
||||
import type { PointRule } from "@/types/Point";
|
||||
|
||||
/**
|
||||
* 查询一组事件可用的自定义积分范围,并返回所有规则范围的交集。
|
||||
*
|
||||
* @param eventIdList 事件 ID 列表
|
||||
* @returns 可用范围;没有完整有效的 SOURCE_VALUE 规则时返回 undefined
|
||||
*/
|
||||
export async function loadSourceValueRange(eventIdList: string[]): Promise<[number, number] | undefined> {
|
||||
if (!eventIdList.length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const resultList = await Promise.all(eventIdList.map(eventId => PointAPI.ruleList({
|
||||
index: 0,
|
||||
size: 1000,
|
||||
equalsExample: {
|
||||
eventId,
|
||||
status: "ACTIVE"
|
||||
}
|
||||
})));
|
||||
const ruleList = resultList
|
||||
.flatMap(result => result.list || [])
|
||||
.filter(isSourceValueRule);
|
||||
if (!ruleList.length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const rangeList = ruleList
|
||||
.map(rule => ({ min: rule.conditionJson?.min, max: rule.conditionJson?.max }))
|
||||
.filter((range): range is { min: number; max: number } => (
|
||||
range.min !== undefined
|
||||
&& range.max !== undefined
|
||||
&& Number.isSafeInteger(range.min)
|
||||
&& Number.isSafeInteger(range.max)
|
||||
&& 0 < range.min
|
||||
&& 0 < range.max
|
||||
));
|
||||
if (rangeList.length !== ruleList.length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const min = Math.max(...rangeList.map(range => range.min), 1);
|
||||
const max = Math.min(...rangeList.map(range => range.max));
|
||||
return min <= max ? [min, max] : undefined;
|
||||
}
|
||||
|
||||
function isSourceValueRule(rule: PointRule): boolean {
|
||||
return rule.status === "ACTIVE" && rule.triggerType === "SOURCE_VALUE" && rule.pointMode === "SOURCE_VALUE";
|
||||
}
|
||||
Reference in New Issue
Block a user