bugfix:条件式の関連修正

This commit is contained in:
xiaozhe.ma
2024-08-02 10:03:55 +09:00
parent 24fca834e0
commit bf4ddba490
3 changed files with 97 additions and 18 deletions

View File

@@ -42,13 +42,10 @@ export class ErrorShowAction implements IAction {
}
this.props = actionNode.ActionValue as IErrorShowProps;
const conditionResult = this.getConditionResult(context);
console.log("条件結果:",conditionResult);
if (conditionResult) {
event.error = this.props.message;
} else {
result = {
canNext: false,
result: true
}
result.canNext=false;
}
return result;
} catch (error) {

View File

@@ -84,8 +84,6 @@ export interface IAction{
register():void;
}
export interface IField{
name?:string;
code:string;
@@ -99,6 +97,14 @@ export interface IVarName{
fields?:IVarName[];
}
/**
* ユーザー、グループ、組織などオブジェクト類型
*/
export interface ICodeValue {
code: string;
name?: string;
}
/**
* アクションのプロパティ定義に基づいたクラス
*/
@@ -297,7 +303,7 @@ export class ErrorManager{
public setEvent(event:any){
const messages = this.errors.map((err)=>{
return `${err.action.name}」処理中例外発生しました。詳細:${err.error}`;
return `${err.action.name}」処理中例外発生しました。\n詳細:${err.error}`;
});
event.error=messages.join('\n');
}

View File

@@ -1,4 +1,4 @@
import { IContext } from "./ActionTypes";
import { IContext,ICodeValue } from "./ActionTypes";
//ノード種別
export enum NodeType{
@@ -315,7 +315,38 @@ export class ConditionTree {
throw new Error('Unsupported node type');
}
}
getCodeValue(value: any): any {
if (value && typeof value === 'object' && 'code' in value) {
return value.code;
} else {
return value;
}
}
/**
* ICodeValue型のcodeに変換する
* @param value
* @returns
*/
convertCodeValue(value:any):any{
if (Array.isArray(value)) {
return value.map(v => this.getCodeValue(v));
} else {
return this.getCodeValue(value);
}
}
/**
*
* @param vars 変数値を取得する
* @param path
* @returns
*/
getContextVarByPath (vars: {[key:string]:any}, path: string){
return path.split(".").reduce((o, k) => (o || {})[k], vars);
};
/**
* Condition objectの値を取得する
* @param object
@@ -331,10 +362,13 @@ export class ConditionTree {
if(fieldValue.type==='NUMBER' && fieldValue.value!==undefined){
return Number(fieldValue.value);
}else{
return fieldValue.value;
return this.convertCodeValue(fieldValue.value);
}
}else if(object.objectType==='variable'){
return context.variables[object.name].value;
const varValue = this.getContextVarByPath(context.variables,object.name.name);
return this.convertCodeValue(varValue);
}else if(object.objectType==='text'){
return object.sharedText;
}
}
@@ -343,10 +377,13 @@ export class ConditionTree {
* @param object
* @returns
*/
getConditionValue(object:any){
getConditionValue(object:any,context:IContext){
if(!object || typeof object!=="object"){
return object;
}
if("objectType" in object){
return this.getObjectValue(object,context);
}
if("sharedText" in object){
return object.sharedText;
}
@@ -369,8 +406,16 @@ export class ConditionTree {
*/
evaluateCondition(condition: ConditionNode, context: IContext): boolean {
const { object, operator, value } = condition;
const targetValue = this.getObjectValue(object,context);
const conditionValue = this.getConditionValue(value);
const targetObject = this.getObjectValue(object,context);
const conditionObject = this.getConditionValue(value,context);
const isArrayTarget = Array.isArray(targetObject);
const isArrayValue = Array.isArray(conditionObject);
//配列の比較
if((isArrayTarget && targetObject.length > 1)||(isArrayValue && conditionObject.length>1)){
return this.compareArray(operator,targetObject,conditionObject)
}
const targetValue = isArrayTarget?targetObject[0]:targetObject;
const conditionValue = isArrayValue?conditionObject[0]:conditionObject;
switch (operator) {
case Operator.Equal:
case Operator.NotEqual:
@@ -427,7 +472,6 @@ export class ConditionTree {
else if (typeof targetValue === 'string') {
value = String(value);
}
switch (operator) {
case Operator.Equal:
return targetValue === value;
@@ -446,6 +490,40 @@ export class ConditionTree {
}
}
/**
* 配列値の比較
* @param operator
* @param targetValue
* @param value
*/
/**
* 配列値の比較
* @param operator
* @param targetValue
* @param value
*/
compareArray(operator: Operator, targetValue: any, value: any): boolean {
const isArrayTarget = Array.isArray(targetValue);
const isArrayValue = Array.isArray(value);
const sortArray = (arr: any[]) => arr.slice().sort();
targetValue = isArrayTarget?targetValue:[targetValue];
value= isArrayValue?value:[value];
const targetArray=sortArray(targetValue);
const valueArray=sortArray(value);
switch (operator) {
case Operator.Equal:
return targetArray.every((v, i) => v === valueArray[i]);
case Operator.NotEqual:
return !targetArray.every((v, i) => v === valueArray[i]);
case Operator.Contains:
return valueArray.every(v => targetArray.includes(v));
case Operator.NotContains:
return !valueArray.every(v => targetArray.includes(v));
default:
return false;
}
}
/**
* 含む計算
* @param targetValue
@@ -482,6 +560,4 @@ export class ConditionTree {
}
return false;
}
}