import { Context, Service } from "egg";
|
import { EntityManager } from "typeorm";
|
import { LoginInfo } from "../entity/sys/loginInfo";
|
import { ResultInfo2 as ResultInfo } from "../public/commonInterface";
|
|
export default class baseApiService extends Service {
|
private _info: ResultInfo;
|
/**
|
* 返回数据结构
|
*/
|
public get info() {
|
return this._info;
|
}
|
public set info(val: ResultInfo) {
|
this._info = val;
|
}
|
|
constructor(ctx: Context) {
|
super(ctx);
|
this._info = {
|
Result: false,
|
Msg: undefined,
|
statusCode: undefined,
|
Data: undefined
|
};
|
}
|
|
public async getToken() {
|
const { ctx } = this;
|
try {
|
const guid = this.ctx.query.guid;
|
ctx.body = {
|
guid
|
};
|
} catch (error) {
|
console.log("------------------" + error);
|
}
|
}
|
|
/**
|
* 主数据,读写
|
*/
|
public get dbWrite(): EntityManager {
|
return this.ctx.service.common.dbWrite;
|
}
|
|
/**
|
* 主数据,只读
|
*/
|
public get dbRead(): EntityManager {
|
return this.ctx.service.common.dbRead;
|
}
|
|
/**
|
* 用户信息
|
*/
|
public get userInfo(): Promise<LoginInfo> {
|
return this.ctx.helper.userInfo();
|
}
|
|
/**
|
* 请求参数
|
*/
|
public get body() {
|
return this.ctx.request.body;
|
}
|
|
/**
|
* 设置账套信息
|
*/
|
public async setAccountInfo(dataInfo) {
|
let userInfo = await this.userInfo;
|
dataInfo.platCorpName = userInfo.platCorpName;
|
dataInfo.platUserCode = userInfo.platUserCode;
|
dataInfo.platUserName = userInfo.platUserName;
|
dataInfo.platUser_Id = userInfo.platUser_Id;
|
dataInfo.userProductAlias = userInfo.userProductAlias;
|
dataInfo.userProductCode = userInfo.userProductCode;
|
dataInfo.userProduct_Id = userInfo.userProduct_Id;
|
|
// 设置新建信息
|
let keyValue = dataInfo[this.body.idField];
|
if (!keyValue) {
|
dataInfo = Object.assign(dataInfo, {
|
createID: userInfo.user_Id,
|
creator: userInfo.userTrueName,
|
createDate: new Date()
|
});
|
} else {
|
// 设置修改信息
|
dataInfo = Object.assign(dataInfo, {
|
modifyID: userInfo.user_Id,
|
modifier: userInfo.userTrueName,
|
modifyDate: new Date()
|
});
|
}
|
}
|
}
|