Merged PR 94: feat:#608月末算出,#607日付指定

feat:#608月末算出,#607日付指定

Related work items: #607, #608
This commit is contained in:
Yu Wang
2024-09-13 00:29:31 +00:00
committed by Takuto Yoshida(タクト)
3 changed files with 165 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
import { actionAddins } from ".";
import { IAction, IActionResult, IActionNode, IActionProperty, IField ,IContext, IVarName} from "../types/ActionTypes";
/**
* アクションの属性定義
*/
interface IDateSpecifiedProps {
verNameGet:string;
newYear:number;
newMonth:number;
newDay:number;
verName:IVarName;
}
/**
* 日付指定アクション
*/
export class DateSpecifiedAction implements IAction {
name: string;
actionProps: IActionProperty[];
props: IDateSpecifiedProps;
constructor() {
this.name = "日付指定";
this.actionProps = [];
this.props = {
verNameGet:'',
newYear:0,
newMonth:0,
newDay:0,
verName:{name:''}
}
this.register();
}
/**
* アクションの実行を呼び出す
* @param actionNode
* @param event
* @returns
*/
async process(actionNode: IActionNode, event: any,context:IContext): Promise<IActionResult> {
let result = {
canNext: true,
result: false
};
try {
//属性設定を取得する
this.actionProps = actionNode.actionProps;
if (!('verName' in actionNode.ActionValue) && !('verNameGet' in actionNode.ActionValue) ) {
return result
}
this.props = actionNode.ActionValue as IDateSpecifiedProps;
////////////////////////////////////////////////////////////////////////////////////////////////
//本番コード開始:
//取得変数の値を呼び出して代入する:
const getContextVarByPath = (obj: any, path: string) => {
return path.split(".").reduce((o, k) => (o || {})[k], obj);
};
let verNameGetValue = getContextVarByPath(context.variables,this.props.verNameGet);
////////////////////////////////////////////////////////////////////////////////////////////////
//取得変数の値Dateオブジェクトに変換
let dateObj = new Date(verNameGetValue);
// 年の設定newYearが設定されていない場合は、元の値を使用
dateObj.setFullYear(this.props.newYear >=1900 && this.props.newYear <=9999 ? this.props.newYear : dateObj.getFullYear());
// 月の設定newMonthが設定されていない場合は、元の値を使用// 月は0始まりなので、12月は11。
dateObj.setMonth(this.props.newMonth >=1 && this.props.newMonth <=12 ? this.props.newMonth-1 : dateObj.getMonth());
// 日の設定newDayが設定されていない場合は、元の値を使用
dateObj.setDate(this.props.newDay >=1 && this.props.newDay <=31 ?this.props.newDay : dateObj.getDate());
// 変数に新しい値を設定
if(this.props.verName && this.props.verName.name!==''){
context.variables[this.props.verName.name]=dateObj.toISOString();
}
////////////////////////////////////////////////////////////////////////////////////////////////
result = {
canNext:true,
result:true
}
return result;
}catch(error){
context.errors.handleError(error,actionNode);
result.canNext=false;
return result;
}
};
register(): void {
actionAddins[this.name] = this;
}
}
new DateSpecifiedAction();

View File

@@ -0,0 +1,77 @@
import { actionAddins } from ".";
import { IAction, IActionResult, IActionNode, IActionProperty, IField ,IContext, IVarName} from "../types/ActionTypes";
/**
* アクションの属性定義
*/
interface IEndOfMonthProps {
verNameGet:string;
verName:IVarName;
}
/**
* 月末算出アクション
*/
export class EndOfMonthAction implements IAction {
name: string;
actionProps: IActionProperty[];
props: IEndOfMonthProps;
constructor() {
this.name = "月末算出";
this.actionProps = [];
this.props = {
verNameGet:'',
verName:{name:''}
}
this.register();
}
/**
* アクションの実行を呼び出す
* @param actionNode
* @param event
* @returns
*/
async process(actionNode: IActionNode, event: any,context:IContext): Promise<IActionResult> {
let result = {
canNext: true,
result: false
};
try {
//属性設定を取得する
this.actionProps = actionNode.actionProps;
if (!('verName' in actionNode.ActionValue) && !('verNameGet' in actionNode.ActionValue) ) {
return result
}
this.props = actionNode.ActionValue as IEndOfMonthProps;
////////////////////////////////////////////////////////////////////////////////////////////////
//本番コード開始:
//取得変数の値を呼び出して代入する:
const getContextVarByPath = (obj: any, path: string) => {
return path.split(".").reduce((o, k) => (o || {})[k], obj);
};
let verNameGetValue = getContextVarByPath(context.variables,this.props.verNameGet);
////////////////////////////////////////////////////////////////////////////////////////////////
//取得変数の値Dateオブジェクトに変換
let dateObj = new Date(verNameGetValue);
// 月末を計算
let year = dateObj.getFullYear();
let month = dateObj.getMonth() + 1; //月は0から始まるため、1を足す
let lastDayOfMonth = new Date(year, month, 0); // 翌月の0日目は今月の月末
if(this.props.verName && this.props.verName.name!==''){
context.variables[this.props.verName.name]=lastDayOfMonth.toISOString();
}
////////////////////////////////////////////////////////////////////////////////////////////////
result = {
canNext:true,
result:true
}
return result;
}catch(error){
context.errors.handleError(error,actionNode);
result.canNext=false;
return result;
}
};
register(): void {
actionAddins[this.name] = this;
}
}
new EndOfMonthAction();

View File

@@ -24,6 +24,8 @@ import '../actions/auto-lookup';
import '../actions/field-disable';
import '../actions/style-field';
import '../actions/datetime-calc';
import '../actions/end-of-month';
import '../actions/date-specified';
import { ActionFlow,ErrorManager,IActionFlow, IActionResult,IContext } from "./ActionTypes";
const ShowErrorEvents:string[] = [
"app.record.create.submit.success",