提交 9eca2e48 编写于 作者: sq3536's avatar sq3536

Merge remote-tracking branch 'origin/master'

import { Http } from '@ibiz-core';
import { Http, RouteTool } from '@ibiz-core';
/**
* 实体服务基类
* @export
......@@ -6,15 +6,39 @@ import { Http } from '@ibiz-core';
*/
export class EntityService{
[key: string]: any;
constructor(opts?: any) {
}
/**
* 实体关系路径集合
* @protected
*/
protected deResPaths: any[] = []
/**
* HTTP服务类
* @protected
*/
protected http = Http.getInstance();
// TODO
/**
* 计算请求的实体关系路径
*
* @protected
* @param context 视图上下文
* @param isSelfAppend 是否拼接实体自身的主键值。
*/
protected buildDeResPath(context: any, isSelfAppend: boolean){
let deResPath = RouteTool.buildDeResRequestPath(context,this.deResPaths);
// 不需要自身的主键值的删除末尾/xxxx
if(!isSelfAppend){
deResPath = deResPath.substring(0,deResPath.lastIndexOf("/"))
}
return deResPath;
}
// TODO 预置方法
public GET(){}
}
\ No newline at end of file
......@@ -34,12 +34,13 @@ export class RouteTool {
* @memberof RouteTool
*/
public static getIndexRoutePath(route: any): string {
const parameterName = route.meta?.parameters?.[0]?.pathName || "apps";
const parameter = route.meta?.parameters?.[0] || { pathName: "apps", parameterName: "app" };
const {pathName, parameterName} = parameter;
const param = route.params[parameterName];
if (notEmpty(param)) {
return `/${parameterName}/${param}`;
return `/${pathName}/${param}`;
}
return `/${parameterName}`;
return `/${pathName}`;
}
/**
......@@ -47,6 +48,7 @@ export class RouteTool {
* - 优先匹配路径节点数多的路径
* - 取最终匹配节点个数最多的组合
* - 路径节点必须从后往前连续匹配,中间缺失的舍弃前面匹配的节点
* - 一个也没匹配返回/{实体自身的pathName}
*
* @static
* @param {*} [viewParam={}] 视图上下文
......@@ -105,6 +107,7 @@ export class RouteTool {
* - 优先匹配路径节点数多的路径
* - 取最终匹配节点个数最多的组合
* - 路径的每个节点必须全部匹配
* - 一个也没匹配返回/{实体自身的pathName}/undefined
*
* @static
* @param {*} [viewParam={}] 视图上下文
......@@ -150,6 +153,11 @@ export class RouteTool {
}
});
// 如果一个匹配的没有,即没有任何主键匹配上,关系路径为实体自身的/pathName/undefined
if(routePath == ''){
routePath = "/"+deResPaths[deResPaths.length -1][0].pathName+"/undefined";
}
return routePath;
}
......
......@@ -11,56 +11,96 @@ export class {{pascalCase appEntity.codeName}}ServiceBase extends EntityService
constructor(opts?: any) {
super(opts);
// 初始化关系实体路径集合
this.deResPaths = [
{{#each appEntity.appEntityResources as |appEntityResource| }}
{{appEntityResource.deResPaths}}{{#unless @last}},{{/unless}}
{{/each}}
]
}
protected APPDENAME = "{{pascalCase appEntity.codeName}}";
protected SYSTEMNAME = '{{apps.psSystem.codeName}}';
protected APPNAME = '{{apps.codeName}}';
protected APPDENAME = '{{appEntity.codeName}}';
protected APPDENAMEPLURAL = "{{pascalCase appEntity.codeName}}";
{{#if appEntity.keyPSAppDEField}}
protected APPDEKEY = "{{pascalCase appEntity.keyPSAppDEField.codeName}}";
{{/if}}
{{#if appEntity.majorPSAppDEField}}
protected APPDETEXT = "{{pascalCase appEntity.majorPSAppDEField.codeName}}";
{{/if}}
{{#each appEntity.allPSAppDEMethods as |singleAppMethod| }}
/**
* {{singleAppMethod.codeName}}
*
* @param {*} [_context={}]
* @param {*} [_data = {}]
* @returns {Promise<any>}
* @memberof {{pascalCase appEntity.codeName}}ServiceBase
*/
async {{singleAppMethod.codeName}}(_context: any = {}, _data: any = {}): Promise<any> {
//{{singleAppMethod}}
//{{singleAppMethod.psDEServiceAPIMethod}}
//{{singleAppMethod.psDEServiceAPIMethod.requestMethod}}
{{#eq singleAppMethod.methodType "SELECT" }}
const res = await this.http.post(`/{{pluralize appEntity.codeName}}/${encodeURIComponent(_context.{{lowerCase appEntity.codeName}})}{{singleAppMethod.requestPath}}`, _data);
return res;
{{/eq}}
{{#eq singleAppMethod.methodType "FETCH" }}
const res = await this.http.post(`/{{pluralize appEntity.codeName}}/${encodeURIComponent(_context.{{lowerCase appEntity.codeName}})}{{singleAppMethod.requestPath}}`, _data);
return res;
{{/eq}}
{{#eq singleAppMethod.methodType "GET" }}
const res = await this.http.get(`/{{pluralize appEntity.codeName}}/${encodeURIComponent(_context.{{lowerCase appEntity.codeName}})}{{singleAppMethod.requestPath}}`);
return res;
{{/eq}}
{{#eq singleAppMethod.codeName "GetDraft" }}
_data[this.APPDENAME?.toLowerCase()] = undefined;
_data[this.APPDEKEY] = undefined;
const res = await this.http.post(`/{{pluralize appEntity.codeName}}/${encodeURIComponent(_context.{{lowerCase appEntity.codeName}})}{{singleAppMethod.requestPath}}`, _data);
return res;
{{/eq}}
{{#eq singleAppMethod.codeName "Update" }}
const res = await this.http.post(`/{{pluralize appEntity.codeName}}/${encodeURIComponent(_context.{{lowerCase appEntity.codeName}})}{{singleAppMethod.requestPath}}`, _data);
return res;
{{/eq}}
{{#eq singleAppMethod.codeName "Get" }}
const res = await this.http.get(`/{{pluralize appEntity.codeName}}/${encodeURIComponent(_context.{{lowerCase appEntity.codeName}})}{{singleAppMethod.requestPath}}`, _data);
return res;
{{/eq}}
{{#each appEntity.allPSAppDEMethods as |singleAppMethod| }}
{{#if singleAppMethod.psDEServiceAPIMethod}}
/**
* {{singleAppMethod.codeName}}
*
* @param {*} [context={}]
* @param {*} [viewParams = {}]
* @returns {Promise<any>}
* @memberof {{pascalCase appEntity.codeName}}ServiceBase
*/
async {{singleAppMethod.codeName}}(context: any = {}, viewParams: any = {}): Promise<any> {
{{#if (eq singleAppMethod.methodType "SELECT")}}
let deResPath = this.buildDeResPath(context, true);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(deResPath+'/{{singleAppMethod.psDEServiceAPIMethod.requestPath}}', viewParams);
{{else if (eq singleAppMethod.methodType "FETCHTEMP")}}
let deResPath = this.buildDeResPath(context, false);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(deResPath+'/{{singleAppMethod.psDEServiceAPIMethod.requestPath}}', viewParams);
{{else if (eq singleAppMethod.methodType "FETCH")}}
let deResPath = this.buildDeResPath(context, false);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(deResPath+'/{{singleAppMethod.psDEServiceAPIMethod.requestPath}}', viewParams);
// TODO @executeafterbatchaction
{{else if (eq singleAppMethod.codeName "GetDraft")}}
viewParams[this.APPDENAME?.toLowerCase()] = undefined;
viewParams[this.APPDEKEY] = undefined;
let deResPath = this.buildDeResPath(context, false);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(deResPath+'/{{singleAppMethod.psDEServiceAPIMethod.requestPath}}', viewParams);
// TODO appentityexecuteafteractionlogic
// TODO @appentityexecuteafteractionlogic
// TODO 设置本地缓存 @setStore
{{!-- 无参数情况 --}}
{{else if (eq singleAppMethod.psDEServiceAPIMethod.requestParamType "NONE") }}
let deResPath = this.buildDeResPath(context, false);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(deResPath+'/{{singleAppMethod.psDEServiceAPIMethod.requestPath}}', viewParams);
// TODO 设置本地缓存 @setStore
{{!-- 指定属性情况 --}}
{{else if (eq singleAppMethod.psDEServiceAPIMethod.requestParamType "FIELD") }}
{{#if singleAppMethod.psDEServiceAPIMethod.requestMethod "GET"}}
let deResPath = this.buildDeResPath(context, true);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(deResPath+'/{{singleAppMethod.psDEServiceAPIMethod.requestPath}}', viewParams);
// TODO @executeafteraction
// TODO 设置本地缓存 @setStore
{{else}}
let deResPath = this.buildDeResPath(context, true);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(deResPath+'/{{singleAppMethod.psDEServiceAPIMethod.requestPath}}', viewParams);
{{/if}}
{{else if (and (eq singleAppMethod.psDEServiceAPIMethod.requestParamType "ENTITY") (eq singleAppMethod.codeName "Create") ) }}
// TODO 设置本地缓存 @setStore
// @executebeforeaction
if (!viewParams.srffrontuf || viewParams.srffrontuf != 1) {
viewParams[this.APPDEKEY] = null;
}
if (viewParams.srffrontuf != null) {
delete viewParams.srffrontuf;
}
let deResPath = this.buildDeResPath(context, false);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(deResPath+'/{{singleAppMethod.psDEServiceAPIMethod.requestPath}}', viewParams);
{{else}}
// TODO 设置本地缓存 @setStore
// @executebeforeaction
let deResPath = this.buildDeResPath(context, true);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(deResPath+'/{{singleAppMethod.psDEServiceAPIMethod.requestPath}}', viewParams);
{{/if}}
return res;
{{!-- TODO主实体的差异部分 --}}
//{{singleAppMethod.psDEServiceAPIMethod.requestPath}}
//{{singleAppMethod.psDEServiceAPIMethod.requestParamType}}
{{!-- TODO 当为非主实体时,避免无主接口方法返回值异常报错(没遇到这种情况) --}}
}
{{/if}}
{{/each}}
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册