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

Merge remote-tracking branch 'origin/master'

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