提交 76a929ed 编写于 作者: tony001's avatar tony001

update:更新数据服务逻辑

上级 069b6cd5
/**
* {{singleAppMethod.codeName}}
*
* @param {IContext} [context={}]
* @param {IParam} [data = {}]
* @returns {Promise<any>}
* @memberof {{pascalCase appEntity.codeName}}ServiceBase
*/
public async {{singleAppMethod.codeName}}(context: IContext = {}, data: IParam = {}): Promise<any> {
{{#if (eq singleAppMethod.methodType "SELECT")}}
{{! 方法类型为SELECT }}
const deResPath = this.buildDeResPath(context, true);
{{#if (or (eq singleAppMethod.psDEServiceAPIMethod.requestMethod "PUT") (eq singleAppMethod.psDEServiceAPIMethod.requestMethod "POST") )}}
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(`${deResPath}{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestPath}}`,data);
{{else}}
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(`${deResPath}{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestPath}}`);
{{/if}}
{{else if (eq singleAppMethod.methodType "FETCHTEMP")}}
{{! 方法类型为FETCHTEMP }}
const deResPath = this.buildDeResPath(context, false);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(`${deResPath}{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestPath}}`);
{{else if (eq singleAppMethod.methodType "FETCH")}}
{{! 方法类型为FETCH }}
const deResPath = this.buildDeResPath(context, false);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(`${deResPath}{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestPath}}`);
{{else}}
{{! 方法类型为DEACTION }}
this.beforeExecuteAction(context,data,'{{singleAppMethod.codeName}}');
{{#if (eq singleAppMethod.psDEServiceAPIMethod.requestParamType "NONE")}}
{{! 参数类型为NONE,包含GetDraft }}
const deResPath = this.buildDeResPath(context, false);
{{#if (neq singleAppMethod.codeName 'GetDraft')}}
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(`${deResPath}{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestPath}}`);
{{else}}
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(`${deResPath}{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestPath}}`,data);
{{/if}}
{{else if (eq singleAppMethod.psDEServiceAPIMethod.requestParamType "FIELD")}}
{{! 参数类型为FIELD,包含Get,Remove }}
const deResPath = this.buildDeResPath(context, true);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(`${deResPath}{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestPath}}`);
{{else if (eq singleAppMethod.psDEServiceAPIMethod.requestParamType "ENTITY")}}
{{! 参数类型为ENTITY,包含CheckKey,Create,Save,Update }}
{{#if (eq singleAppMethod.codeName "Create")}}
const deResPath = this.buildDeResPath(context, false);
{{else}}
const deResPath = this.buildDeResPath(context, true);
{{/if}}
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(`${deResPath}{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestPath}}`,data);
{{else}}
{{! 参数类型为URIPARAM }}
const deResPath = this.buildDeResPath(context, true);
const res = await this.http.{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestMethod }}(`${deResPath}{{lowerCase singleAppMethod.psDEServiceAPIMethod.requestPath}}`,data);
{{/if}}
this.afterExecuteAction(context,data,'{{singleAppMethod.codeName}}');
{{/if}}
return res;
}
\ No newline at end of file
import { Http, IParam, EntityService } from '@core';
import { IContext, IParam, EntityService } from '@core';
/**
* {{appEntity.logicName}}服务对象基类
......@@ -17,96 +17,40 @@ export class {{pascalCase appEntity.codeName}}ServiceBase extends EntityService
*/
constructor(opts: IParam = {}) {
super(opts,'{{pascalCase appEntity.codeName}}');
// 初始化关系实体路径集合
this.deResPaths = [
{{#each appEntity.appEntityResources as |appEntityResource| }}
{{appEntityResource.deResPaths}}{{#unless @last}},{{/unless}}
{{/each}}
]
}
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| }}
{{#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);
* 初始化基础数据
*
* @protected
* @memberof ChartDataServiceBase
*/
protected initBasicData() {
this.appEntityCodeName = '{{lowerCase appEntity.codeName}}';
this.appEntityCodeNames = '{{pluralize appEntity.codeName}}';
{{#if appEntity.keyPSAppDEField}}
this.appEntityKeyCodeName = '{{lowerCase appEntity.keyPSAppDEField.codeName}}';
{{/if}}
return res;
{{!-- TODO主实体的差异部分 --}}
//{{singleAppMethod.psDEServiceAPIMethod.requestPath}}
//{{singleAppMethod.psDEServiceAPIMethod.requestParamType}}
{{!-- TODO 当为非主实体时,避免无主接口方法返回值异常报错(没遇到这种情况) --}}
{{#if appEntity.majorPSAppDEField}}
this.appEntityTextCodeName = '{{lowerCase appEntity.majorPSAppDEField.codeName}}';
{{/if}}
// 初始化关系实体路径集合
this.deResPaths = [
{{#each appEntity.appEntityResources as |appEntityResource| }}
{{appEntityResource.deResPaths}}{{#unless @last}},{{/unless}}
{{/each}}
]
}
{{#each appEntity.allPSAppDEMethods as |singleAppMethod| }}
{{! 非内置行为才输出 }}
{{#if (eq isBuiltinMethod false)}}
{{! 存在接口方法才输出 }}
{{#if singleAppMethod.psDEServiceAPIMethod}}
{{! 远端接口 }}
{{> @macro/entity/service-remote-method.hbs singleAppMethod=singleAppMethod}}
{{/if}}
{{/if}}
{{/each}}
}
\ No newline at end of file
import { Http, IParam, RouteUtil } from '@core';
import { Http, IContext, IParam, RouteUtil } from '@core';
/**
* 实体服务基类
* @export
......@@ -22,7 +22,43 @@ export class EntityService {
* @type {any[]}
* @memberof EntityService
*/
protected deResPaths: any[] = []
protected deResPaths: any[] = [];
/**
* 应用实体代码名
*
* @protected
* @type {string}
* @memberof EntityService
*/
protected appEntityCodeName: string = '';
/**
* 应用实体代码名(复数形式)
*
* @protected
* @type {string}
* @memberof EntityService
*/
protected appEntityCodeNames: string = '';
/**
* 应用实体主键属性代码名
*
* @protected
* @type {string}
* @memberof EntityService
*/
protected appEntityKeyCodeName: string = '';
/**
* 应用实体主信息属性代码名
*
* @protected
* @type {string}
* @memberof EntityService
*/
protected appEntityTextCodeName: string = '';
/**
* HTTP服务类
......@@ -41,8 +77,17 @@ export class EntityService {
*/
constructor(opts: IParam = {}, dbName?: string, storageMode?: 0 | 1 | 3) {
this.context = opts;
this.initBasicData();
}
/**
* 初始化基础数据
*
* @protected
* @memberof EntityService
*/
protected initBasicData() { }
/**
* 计算请求的实体关系路径
*
......@@ -52,7 +97,7 @@ export class EntityService {
* @return {*}
* @memberof EntityService
*/
protected buildDeResPath(context: any, isSelfAppend: boolean) {
protected buildDeResPath(context: IContext, isSelfAppend: boolean) {
let deResPath = RouteUtil.buildDeResRequestPath(context, this.deResPaths);
// 不需要自身的主键值的删除末尾/xxxx
if (!isSelfAppend) {
......@@ -61,4 +106,51 @@ export class EntityService {
return deResPath;
}
/**
* 执行行为之前
*
* @protected
* @param {IContext} context 应用上下文
* @param {IParam} data 视图参数
* @param {string} method 方法名
* @memberof EntityService
*/
protected beforeExecuteAction(context: IContext, data: IParam, method: string) {
if (!method) return;
switch (method) {
// 新建删除接口无效属性
case 'Create':
if (!data.srffrontuf || data.srffrontuf != 1) {
data[this.appEntityCodeName] = null;
}
if (data.srffrontuf != null) {
delete data.srffrontuf;
}
break;
// 加载草稿删除接口无效属性
case 'GetDraft':
delete data[this.appEntityCodeName];
if (this.appEntityKeyCodeName) {
delete data[this.appEntityKeyCodeName];
}
break;
default:
break;
}
}
/**
* 执行行为之后
*
* @protected
* @param {IContext} context 应用上下文
* @param {IParam} data 视图参数
* @param {string} method 方法名
* @memberof EntityService
*/
protected afterExecuteAction(context: IContext, data: IParam, method: string) {
if (!method) return;
}
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册